Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Use the following Guidelines: Give identifiers semantic meaning and make them easy to read (examples numStudents, grossPay, etc). Keep identifiers to a reasonably short length.

Use the following Guidelines: Give identifiers semantic meaning and make them easy to read (examples numStudents, grossPay, etc). Keep identifiers to a reasonably short length. User upper case for constants. Use title case (first letter is upper case) for classes. Use lower case with uppercase word separators for all other identifiers (variables, methods, objects). Use tabs or spaces to indent code within blocks (code surrounded by braces). This includes classes, methods, and code associated with ifs, switches and loops. Be consistent with the number of spaces or tabs that you use to indent. Use white space to make your program more readable. Reasonably good amount of comments should be added in your program so that it is easy for other people to understand it. Please see the comment style in the textbook. Important Note: All submitted assignments must begin with the descriptive comment block. To avoid losing trivial points, make sure this comment header is included in every assignment you submit, and that it is updated accordingly from assignment to assignment. //*********************************************************** // Name: your name // Title: title of the source file // Description: Write the description in your words. // Time spent: how long it took you to complete the assignment // Date: the date you programmed //********************************************************** Part 1: Writing Exercise: (5 pts) The following are the exercises about the loops in Java. Write the answers in a comment block before the code of Part2. a. What is the output of the following code? (2 pts) int i =0; do { System.out.println("i is : " + i); i++; }while(i < 5); b. How many times will the System.out.println(*); statement execute inside of the following nested forloops? (1 pt) for (j=0; j<10; j++) for (k=10;k>j;k--) System.out.println("*"); c. A data verification loop is a loop that asks the user to input a value within a restricted range repeatedly until the user has input a value within the requested range. Write a data verification loop that that inputs an int value x within the range 0 and 100. Write only partial code and assume Scanner has been imported. (2pts) Note: The answers to the questions (a through c) above should be typed in the block of comments in the java file such as; Part 2: Programming (15 points) Algorithms and Output Specification Implementation Details for the Bank Account For Assignment 4 you have to modify Assignment3 by adding error checking and performing multiple transactions instead of one transaction. Creating the Bank Account - Initial Amount for Saving and Checking: The program will check to make sure the amount entered is positive. If it is not, the error message will be displayed and the amount must be re-entered. The program will continue to display the error message and prompt the user until the user enters a valid number. For example: Initial deposit into Savings: -99 Invalid choice (number must be positive). Initial deposit into Savings: 0 Invalid choice (number must be positive). Initial deposit into Savings: 1000 The program will then ask for an initial deposit into checking. The error checking will be the same as for savings. For example: Initial deposit into Checking: -99 Invalid choice (number must be positive). Initial deposit into Checking: 500 Note: Only positive nonzero amounts are acceptable. Although it is reasonable that someone could open a bank account with $0 in either checking or savings, for this program there must be something in each account. The Main Menu Display If the user enters a number that is not between 1 and 4, the program will display the message "Invalid choice (not an option)." and then display the same prompt. For example: Bank Options: 1. Deposit Money 2. Withdraw Money 3. Transfer Money 4. Quit Your choice: 6 Invalid choice (not an option). Your choice: 0 Invalid choice (not an option). Your choice: 1 After the action the user choice is completed this same menu will be displayed again. 1. Deposit Money The first option is to deposit money. When the user selects this option, the following menu is displayed: Deposit Money Options: 1. Deposit to Checking 2. Deposit to Savings 3. Cancel Your choice: Similar to the other menus, any choice that is not in the valid range (1-3) will display the same error message "Invalid choice (not an option)." and then display the same options and prompt. For example: Deposit Money Options: 1. Deposit to Checking 2. Deposit to Savings 3. Cancel Your choice: 6 Invalid choice (not an option). Your choice: 0 Invalid choice (not an option). Your choice: 1 Once a valid option has been chosen, the action is taken. If the user chooses option 3 (Cancel) "Cancel Deposit." is displayed and the program is returned to the main menu. If they choose 1 or 2 the prompt is displayed asking for the amount to be deposited. It can be either for checking or for savings. The error checking for the amount entered is the same as that for the initial deposit. For example (replace "Checking" with "Savings" if appropriate): Deposit Money Options: 1. Deposit to Checking 2. Deposit to Savings 3. Cancel Your choice: 1 Amount to deposit to Checking: 0 Invalid choice (number must be positive). Amount to deposit to Checking: -99 Invalid choice (number must be positive). Amount to deposit to Checking: 150 After the amount is successfully entered, a final message is displayed (replace "Checking" with "Savings" when appropriate): You deposited $150.00 to Checking. 2. Withdraw Money The second option is to withdraw money. When the user selects this option, the following menu is displayed: Withdraw Money Options: 1. Withdraw from Checking 2. Withdraw from Savings 3. Cancel Your choice: Similar to the other menus, any choice that is not in the valid range (1-3) will display the same error message "Invalid choice (not an option)." and then display the same options and prompt. For example: Withdraw Money Options: 1. Withdraw from Checking 2. Withdraw from Savings 3. Cancel Your choice: 6 Invalid choice (not an option). Your choice: 0 Invalid choice (not an option). Your choice: 1 Once a valid option is chosen, the action is taken. If the user chooses option 3 (Cancel) "Cancel Withdraw." is displayed and they are just returned to the main menu (see the sample executions for an example). If they choose 1 or 2 the prompt is displayed asking for the amount to be withdrawn. It can be either for checking: Amount to withdraw from Checking: or for savings: Amount to withdraw from Savings: The error checking for the amount entered is slightly different than that for the deposits. In addition to checking for a positive number, you must check that the user does not withdraw more money than they have in the account. For example, (replace "Checking" with "Savings" if appropriate): Withdraw Money Options: 1. Withdraw from Checking 2. Withdraw from Savings 3. Cancel Your choice: 1 Amount to withdraw from Checking: 3000 Invalid choice (you don't have that much in your Checking). Amount to withdraw from Checking: 0 Invalid choice (number must be positive). Amount to withdraw from Checking: -99 Invalid choice (number must be positive). Amount to withdraw from Checking: 250 You withdrew $250.0 from Checking. After the amount is successfully entered, a final message is displayed as seen above (replace "Checking" with "Savings" when appropriate). 3. Transfer Money The third option is to transfer money. When the user selects this option, the following menu is displayed: Transfer Money Options: 1. Transfer from Checking to Savings 2. Transfer from Savings to Checking 3. Cancel Your choice: Similar to the other menus, any choice that is not in the valid range (1-3) will display the same error message "Invalid choice (not an option)." and then display the same options and prompt. For example: Transfer Money Options: 1. Transfer from Checking to Savings 2. Transfer from Savings to Checking 3. Cancel Your choice: 6 Invalid choice (not an option). Your choice: 0 Invalid choice (not an option). Your choice: 1 Once a valid option has been chosen, the action is taken. If the user chooses option 3 (Cancel) "Cancel Transfer." is displayed and they are just returned to the main menu (see the sample execution for an example). If they choose 1 or 2 the prompt is displayed asking for the amount to be withdrawn. It can be either for checking: Amount to transfer from Checking to Savings: or for savings: Amount to transfer from Savings to Checking: The error checking for the amount entered is the same as that for withdrawals. The program must check for a positive number and for an amount less than or equal to the amount currently in their account. Two examples below: Example 1 Transfer Money Options: 1. Transfer from Checking to Savings 2. Transfer from Savings to Checking 3. Cancel Your choice: 1 Amount to transfer from Checking to Savings: 0 Invalid choice (number must be positive). Amount to transfer from Checking to Savings: -99 Invalid choice (number must be positive). Amount to transfer from Checking to Savings: 250 You transferred $250.0 from Checking to Savings. Example 2 Transfer Money Options: 1. Transfer from Checking to Savings 2. Transfer from Savings to Checking 3. Cancel Your choice: 2 Amount to transfer from Savings to Checking: 10000 Invalid choice (you don't have that much in your Savings). Amount to transfer from Savings to Checking: 100 You transferred $100.0 from Savings to Checking. Transaction Finished Message After transactions are completed a message is displayed. This is displayed even when the user cancels the selected action (option 3 "Cancel" on the menu): After this transaction your balance is: $1200.0 (S: $1000.0, C: $200.0) Example Execution Run #1: User input is in bold Welcome to CSE110 BANK What is your name? Mike Jones Initial deposit into Savings: 300 Initial deposit into Checking: 450 Mike Jones's Basic Account balance: $750.00 (S: $300.00, C: $450.00) Bank Options: 1. Deposit Money 2. Withdraw Money 3. Transfer Money 4. Quit Your choice: 2 Withdraw Money Options: 1. Withdraw from Checking 2. Withdraw from Savings 3. Cancel Your choice: 4 Invalid choice (not an option). Your choice: 0 Invalid choice (not an option). Your choice: 1 Amount to withdraw from Checking: 650 Invalid choice (you don't have that much in your Checking). Amount to withdraw from Checking: -100 Invalid choice (number must be positive). Amount to withdraw from Checking: 250 You withdrew $250.00 from Checking. Bank Options: 1. Deposit Money 2. Withdraw Money 3. Transfer Money 4. Quit Your choice: 3 Transfer Money Options: 1. Transfer from Checking to Savings 2. Transfer from Savings to Checking 3. Cancel Your choice: 1 Amount to transfer from Checking to Savings: -100 Invalid choice (number must be positive). Amount to transfer from Checking to Savings: 1400 Invalid choice (you don't have that much in your Checking). Amount to transfer from Checking to Savings: 350 Invalid choice (you don't have that much in your Checking). Amount to transfer from Checking to Savings: 110 You transferred $110.00 from Checking to Savings. Bank Options: 1. Deposit Money 2. Withdraw Money 3. Transfer Money 4. Quit Your choice: 4 Thank you for using CSE110 BANK. Goodbye After this transaction your balance is: $500.00 (S: $410.00, C: $90.00) We have added interest to your account! Mike Jones's Basic Account balance: $512.50 (S: $420.25, C: $92.25) Example Execution Run #2: Welcome to CSE110 BANK What is your name? Jill Jones Initial deposit into Savings: 800 Initial deposit into Checking: 100 Jill Jones's Basic Account balance: $900.00 (S: $800.00, C: $100.00) Bank Options: 1. Deposit Money 2. Withdraw Money 3. Transfer Money 4. Quit Your choice: 1 Deposit Money Options: 1. Deposit to Checking 2. Deposit to Savings 3. Cancel Your choice: 1 Amount to deposit to Checking: 1200 You deposited $1,200.00 to Checking. Bank Options: 1. Deposit Money 2. Withdraw Money 3. Transfer Money 4. Quit Your choice: 2 Withdraw Money Options: 1. Withdraw from Checking 2. Withdraw from Savings 3. Cancel Your choice: 2 Amount to withdraw from Savings: 2000 Invalid choice (you don't have that much in your Savings). Amount to withdraw from Savings: -100 Invalid choice (number must be positive). Amount to withdraw from Savings: 200 You withdrew $200.00 from Savings. Bank Options: 1. Deposit Money 2. Withdraw Money 3. Transfer Money 4. Quit Your choice: 4 Thank you for using CSE110 BANK. Goodbye After this transaction your balance is: $1,900.00 (S: $600.00, C: $1,300.00) We have added interest to your account! Jill Jones's Premium Account balance: $1,966.50 (S: $621.00, C: $1,345.50)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Theory And Application Bio Science And Bio Technology International Conferences DTA And BSBT 2011 Held As Part Of The Future Generation In Computer And Information Science 258

Authors: Tai-hoon Kim ,Hojjat Adeli ,Alfredo Cuzzocrea ,Tughrul Arslan ,Yanchun Zhang ,Jianhua Ma ,Kyo-il Chung ,Siti Mariyam ,Xiaofeng Song

2011th Edition

3642271561, 978-3642271564

More Books

Students also viewed these Databases questions

Question

6. Conclude with the same strength as in the introduction

Answered: 1 week ago

Question

7. Prepare an effective outline

Answered: 1 week ago