java code

profileWernerrab
javalastlabproj1.docx

COURSE OBJECTIVES – LEARNING OUTCOME

[LO1]

Provide UML class diagram and the code of data type classes

Provide the pseudo-code or flowchart based on the requirement of a project before writing the code of the driver class. Also, can access data members of data type classes

Describe and implement the inheritance relationship between super class and child classes.

Can use abstract classes or interface and apply polymorphism to the real-life problem project

[LO2]

Describe and implement operations of unsorted/sorted array-based structures

[LO3]

Describe and implement operations of Stack and Queue structures. Using Stack/Queue to the real life problem project

[LO4]

Describe and implement operations of Singly Linked List and Doubly Linked List

[LO5]

Describe and implement operations of Hashed data structure

[LO7]

Describe and implement operations of Binary Search Trees

LAB OBJECTIVES

-Create a new project, add source file to the project, compile and run the program without errors and qualified to the requirement

-Declare variables of int, double, String;

-provide UML of data types

-Create data types with data members, constructors, mutator methods

-Apply Inheritance relationship

-Apply polymorphism in the project

-provide the pseudo-code of program

-create and manage the menu to loop back to re-display after each task: using do.. while

-Use switch statement to determine and define the action for each task

-Format the output in columns and double numbers with 2 decimal digits

-Display message box

-can create a data structure of UnsortedOptimizedArray, Restricted Data Structures: Stack and Queue, Linked List, Hashed, Tree

-can process all operations of UnsortedOptimizedArray, Restricted Data Structures: Stack and Queue, Linked List, Hashed, Tree

-can access data in file .xlxs

NEW CONCEPTS

-process on one data structure that is a data member of one node of other data structure

SKILLS REQUIRED TO DO THIS LAB

Review all skills required from the previous labs and focus on the following:

-Review to create the pseudo-code or a flowchart of a lab

-Review the syntax to create a data type class with data members, constructors, mutator accessor methods, method toString

-Review how to define a child class including data member, constructor, toString and other methods inheriting from parent class:

-Review how to declare an object in main(), how to access the methods of data type classes from main()

-Review how to apply polymorphism

-Review control structure: if..else, switch, do..while loop

-How to set the decimal digits (2) of a double number

-How to display the message box

-How to access on each operation of UnsortedOptimizedArray, Restricted Data Structures: Stack and Queue, Linked List, Hashed, Tree

-How to access file .xlxs

NEW SKILLS:

-Learn how to create and access node of a data structure that is data member of a node in other data structure

HOW TO DO EACH PART

From now and on yourLastName will be changed to your last name

*Step1: Read the requirement of each part.

Provide the UML of class Account_yourLastName, class CheckingAccount_yourLastname, class SavingAccount_yourLastName, class BankCustomer

Provide the pseudo-code or flowchart of main()

*Step2:

-start editor eclipse, create the project with the project name:

SP2020_PROJECT_yourLastName

-add data type classes:

Account_yourLastName.java

CheckingAccount_yourLastName.java

SavingAccount_yourLastName.java

BankCustomer_yourLastName.java

-add data structure classes

Select one that has learned from the course to add in (DO NOT SELECT THE ONE FROM JAVA)

-Add the driver class

SP2020_BankSystem_yourLastName (part1)

*Step3: follow UMO and step by step in the pseudo-code to write the java code

*Step4: compile and run the program

*Step5: debug if there are any errors to complete the program

PROJECT INSTRUCTION

DATA TYPE CLASSES

-Reuse the class Account_yourLastName, CheckingAccount_yourLastName, SavingAccount_yourLastName from the previous lab WITH MAKE THE FOLLOWING CHANGES:

class Account_yourLastName:

* add a data member:

protected String statement and initialize in each constructor to empty String

* add the method setMonthlyStatement() and method getMonthlyStatement() as below:

public void setMonthlyStatement()

{

statement = String.format("%-25s%10s\n", "Account Number:", accountNumber) +

String.format("%-25s%10.1f\n", "Balance:", balance);

}

public String getMonthlyStatement()

{

return statement;

}

Class CheckingAccount_yourLastName

* add the method setMonthlyStatement() as below:

public void setMonthlyStatement()

{

String str = String.format("%-15s%20s\n", "Account Type:", "Checking Account") + super.getMonthlyStatement() +

String.format("%-25s%10.1f\n", "Service Fee:", serviceFee);

balance = balance - serviceFee;

statement = str + String.format("%-25s%10.1f\n", "New balance:", balance);

}

*if the class CheckingAccount_yourLastName does not have the following field then add it in

private float minimumAmount;

set it to 20 in no-argument constructor and pass the value to parameter constructor to initialize a below, for example:

//constructor

public CheckingAccount()

{

super();

serviceFee = 10;

minimumAmount = 20;

}

public CheckingAccount(String num, float money, float fee, float min)

{

super(num, money);

serviceFee = fee;

minimumAmount = min;

}

Class SavingAccount_yourLastName

* add the method setMonthlyStatement() as below:

public void setMonthlyStatement()

{

String str = String.format("%-15s%20s\n", "Account Type:", "Saving Account") +

super.getMonthlyStatement() +

String.format("%-25s%10.2f%%\n", "Interest Rate:", interestRate * 100);

balance = balance + balance * interestRate;

statement = str + String.format("%-25s%10.2f\n", "New balance:", balance);

}

*if the class SavinggAccount_yourLastName does not have the following field then add it in

private float minimumAmount;

set it to 50 in no-argument constructor and pass the value to parameter constructor to initialize a below, for example:

public SavingAccount()

{

super();

interestRate = 0.0f;

minimumAmount = 50.0f;

}

public SavingAccount(String num, float money, float rate, float min)

{

super(num, money);

interestRate = rate;

minimumAmount = min;

}

Class BankCustomer_yourLastName

This class holds the information of one Bank customer including: customerID (String), lastName (String), firstName(String), username(String), password (String), phone(String), address(String), listAccount(LinkedList)

Also, it must have the following: no-argument constructor, parameter constructor, mutator methods for listAccount, and accessor methods for customerID, username, password, listAccount, compareTo, deepCopy, and toString, etc.

The listAccount to store all the accounts that one customer has.

DRIVER CLASS

Provide the pseudo-code or flowchart then write the code for the application

This project to provide the SP2020_BankSystem_yourLastName that allow the bank employee can do some work on all Bank Customers or on each account of one customer

INPUT FILE

All the information of existing bank customers is stored in the file bankCustomer.xlxs This file is provided from eCampus. After download to save to your folder, open it on your screen, then SAVE AS with the extension csv, bankCustomer.csv

Each line of the file bankCustomer.csv will contain information of one bank customer and each information separated by comma as below:

11112222,Martinez,Luis,bbb,bbb,2147251234, address,1850191232,2000.0,20.0,10.0,1389701422,500.0,100.0,.0005,

The information is got from this line as below:

customerID = 11112222

lastName = Martinez

firstName = Luis

userName = bbb

password = bbb

phone = 2147251234

address = address

List of accounts:

accountNumber = 1850191232

balance = 2000.00

minimuAmount = 20.00

serviceFee = 10.00

accountNumber = 138970142

balance = 500.00

minimuAmount = 100.00

interestRate = 0.05%

Based on the last value of group 4 information of one account, you can recognize if it is checking account or saving account to create the account object

DRIVER CLASS IN main()

Declare the following constants at the top of class

//constant

static final float CHECKING_MINIMUM_AMOUNT = 20.0f;

static final float SAVING_MINIMUM_AMOUNT = 50.0f;

static final float SERVICE_FEE = 10.0f;

static final float INTEREST_RATE = 0.0005f;

When the application runs, first, the application should create one data structure to store the Bank Customer nodes. The type of data structure, you can choose one from the list of data structure types that we have learned from the course: UnsortedOptimizedArray, SinglyLinkedList, SinglyLinkedListIterator, LQHased, or BinarySearchTree

Open file bankCustomer.csv to read.

Each line should be read as a String that is the information of one BankCustomer, then split information by the delimiter comma then assign each piece information to one variable. Create a LinkedList object named as listAccount to store all the accounts this customer has then create one object of BankCustomer then insert to the data structure

At the end of file, close file then the data structure stores all the BankCustomer of the bank system

Display main menu:

SP2020_BankSystem_Martinez.java

MAIN MENU – BANK LUIS MARTINEZ

1. Work on Bank Customers

2. Work on Accounts of One Customer

0. Exit

Type a number from 1 or 2 to next step or 0 to exit;

0. EXIT

Before terminating the program, do the following:

-OPEN THE OUTPUT FILE WITH THE SAME NAME AS ABOVE INPUT FILE (bankCustomer.csv) TO WRITE

-FOR EACH NODE OF A CUSTOMER IN THE DATA STRUCTURE, COMBINE THE INFORMATION OF ONE CUSTOMER TO ONE LINE THAT SEPARATE BY COMMAS THEN WRITE THE OUTPUT FILE FOR NEXT USE

To create one output line, you should provide one method toFile() in the class BankCustomer similar like toString but the information on one line and separated by commas

Provide one new method in the data structure class similar like showAll, write to file and call the toFile() instead of toString()

1.SERVICE: Work on Bank Customers

Display menu:

BankSystem_Martinez.java

TASKS ON ALL BANK CUSTOMERS

1. INSERT - Add new Customer - Open new Account

2. FETCH - Display One Customer With All Accounts

3. DELETE - Remove one Customer

4. UPDATE - Modify information of one Customer

5. UPDATE - Open new account for one Customer

6. SHOWALL - Display all Customers with their accounts

7. Process Monthly Statement for customers on all their accounts

0. DONE

Type a number from 1 to 6 or 0 to exit:

Task DONE comeback the main menu

Task INSERT - Add new Customer - Open new Account

Ask from the keyboard for the information of one customer to create an object of BankCustomer

Insert to data structure

Check if insert success, display message:

One new customer is added - Customer ID: 1111222

Otherwise, display message:

Add new customer not successfully

Task FETCH - Display One Customer With All Accounts

Ask from the keyboard for the ID of customer

Fetch the information of this customer and print in on the screen

If the ID cannot be found then display message: This customer does not exist in the system

Task DELETE - Remove one Customer

Ask from the keyboard for the ID of customer

Delete this customer.

If delete is successful, display message: Delete customer successfully

Otherwise, display message: This customer does not exist in the system or delete not success

Task UPDATE - Modify information of one Customer

Ask from the keyboard for the ID of customer

Fetch to get the customer information

If the customer cannot be found, display message: This customer does not exist in the system

Otherwise, ask for which information users want to modify

Set new value for that information

Update the customer to the data structure

Task UPDATE - Open new account for one Customer

Ask from the keyboard for the ID of customer, then get customer information to get the list Account

Ask for information to create the new account

Add the new account to the listAccount

Set the new list to the customer

Task SHOWALL - Display all Customers with their accounts

Just show all the customer with all information of each customer

Task Process Monthly Statement for customers on all their accounts

Add to the data structure class the following method:

public void processOnAllNodes()

{

LinkedList<Account> listAccount = null;

Account = null;

int count = 0;

depend on the type of data structure, similar to do for showAll,

go to each node do the following:

listAccount = data[i].getListAccount();

for (int j=0; j < listAccount.size(); j++)

{

account = listAccount.get(i);

account.setMonthlyStatement();

count++;

}

}

Display the message("Process statement on " + count + " accounts");

}

In main, the data structure name will call this method

2.SERVICE: Work on Accounts of One Customer

Ask for the ID of customer to work on then get the information of customer from data structure

Declare an object of LinkedList listAccount to read the list of accounts of this customer

Display menu

BankSystem_Martinez.java

TASKS ON ONE CUSTOMER INFORMATTION

1. toString - Display one Customer With All Account

2. SHOW ALL - Display All Accounts

3. FETCH - Display one Account

4. FETCH - Check Current Balance of one Account

5. UPDATE - Change username and password

6. UPDATE - Deposit to one Account

7. UPDATE - Withdraw from one Account

8. UPDATE - Transfer Money from one account to other account

0. DONE

Type a number from 1 to 8 or 0 to exit:

Task DONE comeback the main menu

Task toString - Display one Customer With All Account

Print out the information of one BankCusotmer

Task SHOW ALL - Display All Accounts

Data structure of this part is LinkedList, show all the accounts in the listAccount

Task FETCH - Display one Account

Data structure of this part is LinkedList, just fetch one account in the listAccount

Task FETCH - Check Current Balance of one Account

Ask for account number, the use that account number to read account from listAccount

When you have the account, call the function check current balance

Task UPDATE - Change username and password

Ask for new username, password

Set user name and password for this customer by call accessor methods

Task UPDATE - Deposit to one Account

Ask for account number, the use that account number to read account from listAccount

When you have the account, ask for amount to deposit then call the function deposit

Task UPDATE - Withdraw from one Account

Ask for account number, the use that account number to read account from listAccount

When you have the account, ask for amount to withdraw then call the function withdraw

Task UPDATE - Transfer Money from one account to other account

Ask for account number of the account you want to send the money from, get the account1

Ask for account number of the account you want to send the money to, get the account 2

Ask for amount of money want to transfer

Account1 call withdraw

Account2 call deposit