ICS 22
Homework 1
Due 10/5
- Reminder: we check for cheating (via copying or reuse of code from texts or from lecture) and all students involved with get a grade of zero for this homework.
- Write a Java program that allows the user to manage their checking and savings bank accounts.
- Design sketch: define a Java class, Account, that contains one private int member variable, balance. It should have a constructor that takes a parameter for the initial balance of the newly created account. It should have methods to deposit a specified amount and to withdrawl a specified amount. These methods should not allow invalid operations such as depositing or withdrawing a negative amount or withdrawing more than the acount balance. You may want to add another boolean function, hasSufficientBalance, that tells if this acount has enough money for an intended withdrawl. Write a main method that loops over the following actions: presents a menu (as described below), reads a single character command from the user user, then execute (perform) the appropriate action. Use a switch statement to evaluate the entered user command character.
- Here are the menu commands:
- "Deposit to Checking" queries the user for an amount, then deposits that amount into the checking acount.
- "Deposit to Savings" queries the user for an amount, then deposits that amount into the checking acount.
- "Transfer from Savings to Checking" queries the user for an amount, then transfers that amount from the savings account to the checking acount.
- "Withdrawl from Savings" queries the user for an amount, then withdrawls that amount from the savings acount. It should tell the user how much was withdrawln. If there is insufficient balance, you should print an error message indicating so.
- "Show Balances" displays the balances (in dollars and cents) of both the checking and savings accounts.
- "Quit" allows the user to exit the program.
- I provided a sketchy start to the problem in AccountTest.java available from the ICS 22 web Homework-Starts folder.
- What to turn in:
- Submit a printed listing of your entire Java source code.
- Also submit an electronic copy of your Java sourcd files to the electronic dropboxes for your section available on the ICS NT machines. See the syllabus for information on the name you should give to your submission.