Question

For this assignment, you will implement an “automatic reload” algorithm for an EZ Pass account. You...

For this assignment, you will implement an “automatic reload” algorithm for an EZ Pass account. You may work in pairs for this assignment. However, keep in mind that both students are still responsible for understanding how to code in Matlab.

For the scenario, you will start with $35 in your EZ pass account. And when your account balance drops below $10, the code will automatically reload $25 to the account.

When your matlab code is run, it should at minimum have the following behavior.

Display your current EZ-Pass Balance
Example: Account Balance =$35

Ask the user where they want to drive by displaying text to the workspace and then waiting for user input.
For Example, Matlab should display to the workspace a location as well as the toll cost. You should make these up (don’t use mine). But at minimum, you should have 4 destinations (anywhere you want), and a range of costs. At least one of these costs must be $60 or more.
You should also have an option to end the program, such as option 7 below for “No more driving.”

Where do you want to drive today?

Baltimore-$10
Pittsburg-$30
Boston-$40
Washington DC-$60
Seattle Washington-$200
Moon-$10000000
No more driving-$0

Your code should be able to take the user input (User enters a # 1 through n) and deduct that amount from the user’s EZ Pass Balance.
Also, you should build in some error correction in your code.
If the user does not enter an available option, the code should tell the user that and ask for input again.
Example: User enters 54. The code might say

Sorry, that is not a valid option, please enter another location.

After the toll transaction, your code should display the new EZ Pass account balance.
If the balance drops below $10, the code should reload $25 and notify the user
If the account balance is negative even after the reload, the code should notify the user and remedy the situation to make the balance positive again.
For Example, Matlab could display:

New Account Balance= $5

Reloading $25

Account Balance Now = $30

After each transaction, your code should ask where you want to drive again.
The user should then be prompted to input another location if they wish.
The user may drive as much as they want.
When the user finally decides they do not want to drive anymore, your code should display all the toll transactions in the order they occurred, as well as how much their credit card was charged in automatic reloads.
For Example. Matlab could display:

No more driving! Here is your receipt

Toll Charges= 10

60

30

100000000

40

200

Automatic Reloads has Billed Your Credit Card $20000000000
Thanks for using EZ Pass!!!


Hints for approaching this problem:

Plan out some “pseudo-code” and workflow for how you want to implement your code.

Think about what variables you will need to store throughout the algorithm

Remember, knowing how to use Matlab is knowing how to use Matlab help.

To complete this assignment, you will need to implement function in Matlab that can:

Display text to the workspace
Display variables to the workspace
Take input from the user in the workspace prompt
Perform logic (if, then, else)
Implement loops (for and while loops)
Store data as variables
Perform arithmetic functions on variables

0 0
Add a comment Improve this question Transcribed image text
Answer #1

% Matlab script to simulate "automatic reload” algorithm for an EZ Pass account.
ez_balance = 25;
toll= [];
n=0;
reloads = 0;
fprintf('Account Balance= $%d\n',ez_balance);
choice = input('Where do you want to drive today?\n 1) Baltimore-$10 \n 2) Pittsburg-$30\n 3) Boston-$40\n 4) LA-$70\n 5) Washington DC-$80\n 6) Gainsville-$50\n 7) No more driving-$0 ');
while(choice < 1 || choice > 7)
fprintf('Invalid option.\n');
choice = input('Where do you want to drive today?\n 1) Baltimore-$10 \n 2) Pittsburg-$30\n 3) Boston-$40\n 4) LA-$70\n 5) Washington DC-$80\n 6) Gainsville-$50\n 7) No more driving-$0 ');
end
  
while choice ~= 7
if choice == 1
amount = 10;
elseif choice ==2
amount = 30;
elseif choice == 3
amount = 40;
elseif choice == 4
amount = 70;
elseif choice == 5
amount = 80;
else
amount = 50;
end
n = n + 1;
toll(n) = amount;
ez_balance = ez_balance - amount;
fprintf('New Account Balance= $%d',ez_balance);
if(ez_balance < 10)
fprintf('\nReloading $25');
ez_balance = ez_balance + 25;
reloads = reloads + 25;
fprintf('\nAccount Balance= $%d',ez_balance);
end

if(ez_balance < 0)
amount = ceil((-1*ez_balance)/25);
ez_balance = ez_balance + (amount*25);
reloads = amount*25;
fprintf('\n Reloading $%d',(amount*25));
fprintf('\nAccount Balance= $%d',ez_balance);
end

choice = input('\n\nWhere do you want to drive today?\n 1) Baltimore-$10 \n 2) Pittsburg-$30\n 3) Boston-$40\n 4) LA-$70\n 5) Washington DC-$80\n 6) Gainsville-$50\n 7) No more driving-$0 ');
while(choice < 1 || choice > 7)
fprintf('Invalid option.\n');
choice = input('Where do you want to drive today?\n 1) Baltimore-$10 \n 2) Pittsburg-$30\n 3) Boston-$40\n 4) LA-$70\n 5) Washington DC-$80\n 6) Gainsville-$50\n 7) No more driving-$0 ');
end
end

fprintf('\n\nNo more driving! Here is your receipt : ');
fprintf('\nToll Charges : ');
for i=1:length(toll)
fprintf('\n%d',toll(i));
end
fprintf('\nAutomatic Reloads has Billed Your Credit Card $%d',reloads);
fprintf('\nThanks for using EZ Pass!!!\n');

%end of script

Output:

Add a comment
Know the answer?
Add Answer to:
For this assignment, you will implement an “automatic reload” algorithm for an EZ Pass account. You...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a program called problem4.cpp to implement an automatic teller machine (ATM) following the BankAccount class...

    Write a program called problem4.cpp to implement an automatic teller machine (ATM) following the BankAccount class the we implemented in class. Your main program should initialize a list of accounts with the following values and store them in an array Account 101 → balance = 100, interest = 10% Account 201 → balance = 50, interest = 20% Account 108 → balance = 200, interest = 11% Account 302 → balance = 10, interest = 5% Account 204 → balance...

  • ANSWERS SHOULD BE IN PYTHON You have to implement and test these questions. Use error handling...

    ANSWERS SHOULD BE IN PYTHON You have to implement and test these questions. Use error handling for all questions (The user may insert irrelevant data) 1. Write code to ask the user for a number input. Then, using a loop and any math you see fit, write code which enters the subsequent powers of two for that number to the console. For example, given the user input 3, the code should print 2, 4, and 8 to the console.'

  • Please help me to do my assignment it should be python. Thank you Write a menu-driven...

    Please help me to do my assignment it should be python. Thank you Write a menu-driven program for Food Court. (You need to use functions!) Display the food menu to a user (Just show the 5 options' names and prices - No need to show the Combos or the details!) Ask the user what he/she wants and how many of it. (Check the user inputs) AND Use strip() function to strip your inputs. Keep asking the user until he/she chooses...

  • You are to write a program IN C++ that asks the user to enter an item's...

    You are to write a program IN C++ that asks the user to enter an item's wholesale cost and its markup percentage. It should then display the item's retail price. For example: if the an item's wholesale cost is 5.00 and its markup percentage is 100%, then the item's retail price is 10.00 If an item's wholesale cost is 5.00 and its markup percentage is 50%, then the item's retail price is 7.50 Program design specs. You should have 5...

  • *This question was posted earlier but I want to make sure my code differs from the...

    *This question was posted earlier but I want to make sure my code differs from the other answer* CS50 Assignment 3 and Assignment 4 (Both Due By Sunday March 29 11:59 PM) Assignment 3: Bank Application In a recent lecture, we discussed getting input from the user by using the scanf() function. For your reference, I have included a simple example of using scanf() below: scanf() example: #include int main(void) { int number; printf("Enter a number: "); //prompt the user...

  • •create a new savings account object (for choice 2). •ask the user to enter an initial...

    •create a new savings account object (for choice 2). •ask the user to enter an initial balance which should be greater than 50. If the entered amount is less than 50, the program will ask the user to enter another amount. This continues until an amount greater than 50 is entered. •Set the balance of the savings account object by calling the setBalance() method. •Ask the user to deposit an amount. Deposit that amount and display the balance of the...

  • Programming language: JAVA Implement a superclass Appointment and subclasses OneTime, Daily, and Monthly. An appointment has...

    Programming language: JAVA Implement a superclass Appointment and subclasses OneTime, Daily, and Monthly. An appointment has a description (for example "see the dentist") and a date. Write a method OccursOn (int year, int month, int day) that checks whether the appointment occurs on that date. For example, for a monthly appointment, check whether the day of the month matches. Ask the user to enter a date to check (for example, 2006 10 5), and ask to user if they want...

  • Lance 1. Write a C++ program that manages a user's bank account. The program must but...

    Lance 1. Write a C++ program that manages a user's bank account. The program must but not limited to: (a) Display a menu for the user once the program runs. The menu display should be done through a user defined function with no parameters. The display should look like the below snapshot. (3 marks) ***********Welcome to the Bank Account Manager program helps you make cash withdrawals and deposits (b) Ask the user for his/her full name. (1.5 marks) (c) Ask...

  • Answer using C++ Write a program that will calculate the final sales price of a motorcycle;...

    Answer using C++ Write a program that will calculate the final sales price of a motorcycle; this includes additional optional packages along with sales tax. You may assume that the base? price of the motorcycle is $30,000. First you must ask the user to choose which optional packages they want. The user is only permitted to choose one package. Your program should display a menu of the available packages. The user should enter the package by entering the letter associated...

  • Homework 3: Input Validation 1   Objectives control structures console-based user input using Scanner class writing complete...

    Homework 3: Input Validation 1   Objectives control structures console-based user input using Scanner class writing complete programs using two classes: client and supplier 2   User Interface Specification This is a console-based I/O program. Display should go to System.out (print or println) and the program will get user input using the Scanner class. The flow of execution should be as follows: When the program starts, display a one-line introduction to the user Display a menu with 5 options 1. validate zip...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT