Sie sind auf Seite 1von 5

School of Engineering Business and Technology

LAB #5

OBJECTIVVES
Do this lab, you will have the chance to:
-Review how to deal with the loop: while, do .. while and for loop
-Review how to deal with selection structure: if, if..else, or switch
-Review how to open file to write, write to file and close file
-Review how to open file to read, read the file and close file
-How to manage menu
-Write the code for the data type class: data member, constructors, mutator, accessor, toString and
other methods
-How to declar an object and how to use object to access the members of class.

LAB5 has two parts:
PART 1 Create a word document then answer the following questions:
1. Initialize an int variable named product to 1. Write the while loop that lets the user enter a number.
The number should be multiplied with product and the result stored back to the variable product.
The loop should iterate as long as product contains a value less than 1000. After the loop stop,
display message: product = <value of product> - the loop stops

Scanner keyboard = new Scanner(System.in);

System.out.print("enter a number");
int number = Integer.parseInt(keyboard.nextLine());
int product = 1;

while ( number > 1 || number < 1000)
{ product *= number;
System.out.print("product = "+ product);
break;}

2. Write a do-while loop that asks the user to select a task from the following menu to continue:
1. Task 1
2. Task 2
3. Task 3
4. Exit
Read the selection from the keyboard then write the switch statement:
For task 1, display the message Process of task 1
For task 2, display the message Process of task 2
For task 3, display the message Process of task 3
For task 4, display the message Terminate the program
The do.. while loop ends when users select 4 from the menu
Scanner in = new Scanner( System.in );
boolean run = true;

do {//displaying the menu for user preference
System.out.println("Please select from the following menu... ");
System.out.println(" Task 1");
System.out.println(" Task 2");
System.out.println(" Task 3");
System.out.println(" Exit.");
System.out.print("Please make your selection ==> ");

String selection = in.nextLine();
int choice = Integer.parseInt( selection );
switch( choice ) {
case 1: System.out.println("Process of task 1.");
case 2: System.out.println("Process of task 2.");
case 3: System.out.println("Process of task 3.");
case 4: System.out.println("Program terminated");
System.out.close(); //this quits the loop
break;
default: System.out.println( "you must enter 1,2,3, or 4"); }
}//end of loop
while( run = true ); System.out.println("Bye bye.");
} // end

3. Write a for loop that displays the following set of numbers: 0, 11, 22, 33, 44, 55, 66, 77, 88, 99.
{
int i;
for ( i = 0 ; i < 101 ; i+=11 )
System.out.println( i );
}

4. Write code that does the following: Opens a file named numberList.txt, uses a loop to write the
number 1 through 100 to the file and then close the file

5. Write the code that does the following: Opens the numberList.txt created as above. Read all of the
number from the file and displays them, adds all the numbers, close the file and display the total at
the end.


PART 2 (Write the Java program)
Write the application BankSystem_YourLastName for the bank service. The application should display
the following menu to allow users to do the following tasks:

1. Open new account
2. Current Balance
3. Deposit
4. Withdrawal
5. Change Interest Rate
6. Bank statement
7. Exit

The users can select one task to do the service. After finishing one task, the application will display the
menu again to allow users to continue to work other tasks. The application only terminates when users
want to exit.

For each task, the application will do the following:

Open new account:
-Display the message to ask users to provide the following information: account number, name, and
amount of money to start the account. If the money to start the account is less than 100, display the
message The minimum amount to open a new account should be $100
-After read all information, create an account object to pass all the information to the object then
display the message as follows; the example with account number = 12345, name = Annie Hogan,
amount to start = $200

------------------------------------------------
New Account:
Account Name = Annie Hogan
Account Number = 12345
Start Balance = $200.00
------------------------------------------------

Current Balance: read and display the current balance as the following format, for example
---------------------------------------------
Check Balance:
Account Name = Bill Jones
Account Number = 11111
Current Balance = $2200.00
---------------------------------------------

Deposit: ask and read the amount of money to deposit, re-calculate the balance by adding the deposit
amount to the current balance, for example:
---------------------------------------------
Deposit:
Account Name = Alec Goel
Account Number = 54321
Deposit = $100.00
New Balance = $1300.00
---------------------------------------------

Withdrawal: ask and read the amount of money to withdraw. Withdrawing is denied when the balance
< withdraw amount + $25. Otherwise, recalculate the balance by subtracting a withdraw amount from
the balance.

If withdraw is denied, print out the message:

--------------------------------------------------------------------------------------
Withdrawal:
Account Name = Gary Berg
Account Number = 22222
Withdraw money = $50 - Denied
New Balance = $60
---------------------------------------------------------------------------------------

If withdrawal is successful, print out the following:
------------------------------------------------
Withdrawal:
Account Name = Steward Lee
Account Number = 33333
Withdraw = $100.00
New Balance = $2300.00
---------------------------------------------

Change Interest Rate: display message to ask and read the new interest rate, then set the new interest
rate to the interest rate and display the change
-------------------------------------------------
Change Interest Rate:
Account Name = Relay Clinton
Account Number = 44444
New Interest Rate = .005%
---------------------------------------------

Bank statement: calculate the interest amount based on the balance by using the formula: balance *
interest rate / 100, the calculate the new balance: balance = balance + interest amount and print out the
account information as the following format:
---------------------------------------------
Account Name = Mary Lane
Account Number = 55555
Balance = $2300.00
Interest (.05% ) = $1.15
New Balance = $2301.15
---------------------------------------------

HOW TO DO THE LAB:
-Create the class named BankAccount_yourLastName that holds accountName, accountNumber,
balance, interestRate and have constructor and all the methods that support for each requested tasks.
-Create the controlling class named BankSystem_yourLastName that contains the method main to hold
all the interaction between the application and the users as requested above
Notes:
-When users select one task from 2 to 6 but the account does not exist, the application will display the
message to warn users to open the new account first. To do this, before display the menu, declare an
object of BankAccount and assign it to null. Anytime the users select the option from 2 to 6, check if the
object of BankAccount is not null to continue because if the object of BankAccount goes through the
Create- new- account task, it is created with the requested information passing to the object. Therefore,
the object would not be null

HOW TO SUBMIT THE LAB 5
Submit over eCampus:
1. Part1 answers
2. Class BankAccount_yourLastName.txt
3. Class BankOnlineSystem_yourLastName.txt
4. UML of class BankAccount_yourLastName
5. pseudo-code of method main

HOW TO GRADE THE LAB5

ITEMS SCORES
Question1 1
Question2 1
Question3 1
Question4 1
Question5 1
PART2
UML diagram of BankAccount_yourLastName 1
Pseudo-code of method main 1
Data type class: BankAccount_yourLastName 0.5
Class BankAccount_yourLastName data members 2
Constructors to handle Open New Account task 2
Method getBalance to handle the Current Balance task 1
Method deposit method to handle the deposit task 2
Method withdraw to handle the withdrawal task 2
Method setInterestRate to handle the change Interest Rate task 1
Method bankStatement to handle the bank statement task 2
The controlling class BankOnlineSystem_yourLastName 0.5
Declare object of BankAccount 1
Handle the loop until users select exit 1
Switch statement to manage tasks condition to push open new account first 3
Compile success qualify all the requirements 3
Comment 2
Lab5 scores 30

Das könnte Ihnen auch gefallen