Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Objectives: To gain experience with Java\'s Linked List. Documentation: 1. Expla

ID: 3797588 • Letter: O

Question

Objectives:

To gain experience with Java's Linked List.

Documentation:

1.     Explain the purpose of the program as detail as possible - 8%.

2.     Develop a solution for the problem and mention algorithms to be used -12%

3.     List data structures to be used in solution. - 5%.

4.     Give a description of how to use the program and expected input/output - 5%

5.     Explain the purpose of each class you develop in the program. - 5%.

Programming:

1.     For each method, give the pre and post conditions and invariant, if any - 10%

2.     Program execution according to the requirements given 50%

3.     Naming of program as required 5%

Description of Program

You are to write a program name bankrecord.java that maintains a list of records containing names and phone numbers. The program will prompt the user for a command, execute the command, then prompt the user for another command. The commands must be chosen from the following possibilities:

Show all records

Delete a selected record

Change the first name of a selected record.

Change the last name of a selected record

Add a new record

Change the phone number of a selected record

Withdraw an amount requested by the record

Add a deposit for a selected record

Quit.

The following example illustrates the behavior of each command (user input is in bold)

c:java bankrecord [enter]
A Program for a Bank:

Show all records

Delete a selected record

Change the first name of a selected record.

Change the last name of a selected record

Add a new record

Change the phone number of a selected record

Withdraw an amount requested by the record

Add a deposit for a selected record

Quit.

Enter a command from the list above (9 to quit):   2

No record selected

Show all records

Delete a selected record

Change the first name of a selected record.

Change the last name of a selected record

Add a new record

Change the phone number of a selected record

Withdraw an amount requested by the record

Add a deposit for a selected record

Quit.

Enter a command from the list above (9 to quit): 5

Enter first name: Barry

Enter last name: Drake

Enter phone number: 770-591-8071

Enter balance: $2000.00

Show all records

Delete a selected record

Change the first name of a selected record.

Change the last name of a selected record

Add a new record

Change the phone number of a selected record

Withdraw an amount requested by the customer

Add a deposit for a selected record

Quit.

Enter a command from the list above (10 to quit): 5

Enter first name: Ada

Enter last name: Caswell

Enter phone number: 770-251-3456

Enter balance: $1000.00

MENU DISPLAYED AGAIN

Enter a command from the list above (9 to quit): 1

First Name           Last Name           Phone Number:           Balance.


-------------             -------------                -------------                -------------
Ada                Caswell                770-251-3456                $1000.00
Barry                Drake                770-591-8071                $2000.00

MENU DISPLAYED AGAIN

Enter a command from the list above (9 to quit): 5

Enter first name: Elwood

Enter last name: Havens

Enter phone number: 404-345-8897

Enter balance: $50.00


MENU DISPLAYED AGAIN

Enter a command from the list above (9 to quit): 1

First Name           Last Name           Phone Number:           Balance.
-------------             -------------                -------------                -------------
Ada                Caswell                770-251-3456                $1000.00
Barry                Drake                770-591-8071                $2000.00
Elwood           Havens                404-345-8897                $2000.00


MENU DISPLAYED AGAIN

Enter a command from the list above (9 to quit): 8

[For this activity display the current list of customer]

Enter the First name of the record you want to add a deposit:Elwood

Now enter the last name:Havens

The record is: Elwood Havens who currently has: $50.00

Enter the deposit amount:200.00

This record now has $250.00

MENU DISPLAYED AGAIN

Enter a command from the list above (9 to quit): 4

[For this activity display the current list of customer]

Enter the First name of the record you want to change the last name of: Elwood

Enter the First name of the record you want to change the last name of: Havens

Now enter the new last name: Brown

MENU DISPLAYED AGAIN

Enter a command from the list above (9 to quit): 1

First Name           Last Name           Phone Number:           Balance.
-------------             -------------                -------------                -------------
Elwood                Brown                404-345-8897                $250.00
Ada                Caswel                770-251-3456                $1000.00
Barry                Drake                770-591-8071                $2000.00

MENU DISPLAYED AGAIN

Enter a command from the list above (9 to quit): 4

[For this activity display the current list of customer]

Enter the First name of the record you want to change the last name of: Elwood

Enter the First name of the record you want to change the last name of: Havens

Now enter the new last name:Brown

MENU DISPLAYED AGAIN

Enter a command from the list above (9 to quit): 7

[For this activity display the current list of customer]

Enter the First name of the record you want to withdraw from:Elwood

Now enter the last name: Brown

Enter amount to be withdrawn: 100.00

This record now has $150.00

MENU DISPLAYED AGAIN

Enter a command from the list above (9 to quit): q

Illegal command

Enter a command from the list above (9 to quit): 9

The output of your program must match the format illustrated in this example.

Here are some other additional requirements for this program:

         You may assume that phone number contains no spaces.

         After a deletion, there is no record currently selected

         Each record (first name, last name and phone number) must be stored as an object. These objects must be stored in a Linked List.

         The Linked List must be kept sorted at all times based on last name. Sorting is to be achieved when an insertion or modification is done. NO SORTING ROUTINE IS ALLOWED. ALWAYS INSERT A NEW RECORD OR EDITED RECORD INTO ITS' CORRECT PLACE IN THE LINKED LIST. Note: Changing the last name will require resorting.

         Use as many generic algorithm as you can.

Please display code that was ran.

Explanation / Answer

/** * @fileName BankRecord.java * @author ravi * @since 24/2/17 */ import java.util.LinkedList; import java.util.List; import java.util.Scanner; public class BankRecord { static List customers = new LinkedList(); /** * @param firstName * @param newFirstName */ public static void changeFirstName(String firstName, String lastName, String newFirstName) { boolean flag = true; for (Customer customer : customers) { if (customer.getFirstName().equals(firstName) && customer.getLastName().equals(lastName)) { customer.setFirstName(newFirstName); flag = false; break; } } if (flag) { System.out.println("no record selected"); } } /** * @param firstName * @param lastName * @param newLastName */ public static void changeLastName(String firstName, String lastName, String newLastName) { boolean flag = true; for (Customer customer : customers) { if (customer.getFirstName().equals(firstName) && customer.getLastName().equals(lastName)) { customer.setLastName(newLastName); flag = false; break; } } if (flag) { System.out.println("no record selected"); } sortList(); } /** * @param firstName * @param lastName * @param newPhoneNumber */ public static void changePhoneNumber(String firstName, String lastName, String newPhoneNumber) { boolean flag = true; for (Customer customer : customers) { if (customer.getFirstName().equals(firstName) && customer.getLastName().equals(lastName)) { customer.setPhoneNumber(newPhoneNumber); flag = false; break; } } if (flag) { System.out.println("no record selected"); } } /** * This function display all record */ public static void showAllRecord() { sortList(); if (customers.size() > 0) { System.out.println(String.format("%-20s%-20s%-20s%-20s", "First Name", "Last Name", "Phone Number", "Balance")); System.out.println("-----------------------------------------------------------------------------------------"); for (Customer c : customers) { System.out.println(String.format("%-20s%-20s%-20s$%-18.2f", c.getFirstName(), c.getLastName(), c.getPhoneNumber(), c.getBalance())); } } else { System.out.println(" Record list is empty "); } } /** * * @param firstName * @param lastName */ public static void deleteRecord(String firstName, String lastName) { boolean flag = true; for (Customer customer : customers) { if (customer.getFirstName().equals(firstName) && customer.getLastName().equals(lastName)) { customers.remove(customer); flag = false; break; } } if (flag) { System.out.println("no record selected"); } sortList(); } /** * @param firstName * @param lastName * @param phoneNumber * @param balance */ public static void addRecord(String firstName, String lastName, String phoneNumber, double balance) { customers.add(new Customer(firstName, lastName, phoneNumber, balance)); sortList(); } /** * * @param firstName * @param lastName * @param amount */ public static void withdrawAmount(String firstName, String lastName, double amount) { boolean flag = true; for (Customer customer : customers) { if (customer.getFirstName().equals(firstName) && customer.getLastName().equals(lastName)) { if (customer.getBalance() > amount) { customer.setBalance(customer.getBalance() - amount); System.out.println("This record now has $" + customer.getBalance()); flag = false; break; } else { System.out.println("Insufficient Funds"); } } } if (flag) { System.out.println("no record selected"); } } /** * * @param firstName * @param lastName * @param amount */ public static void depositAmount(String firstName, String lastName, double amount) { boolean flag = true; for (Customer customer : customers) { if (customer.getFirstName().equals(firstName) && customer.getLastName().equals(lastName)) { if (customer.getBalance() > amount) { customer.setBalance(customer.getBalance() + amount); System.out.println("This record now has $" + customer.getBalance()); flag = false; break; } else { System.out.println("Insufficient Funds"); } } } if (flag) { System.out.println("no record selected"); } } public static void main(String[] args) { System.out.println("A Program for a Bank:"); Scanner sc = new Scanner(System.in); int command; int recordNumber; String firstName; String lastName; String newFirstName; String newLastName; String phoneNumber; double amount; do { System.out.println("1.Show all records."); System.out.println("2.Delete a selected record."); System.out.println("3.Change the first name of a selected record."); System.out.println("4.Change the last name of a selected record."); System.out.println("5.Add a new record."); System.out.println("6.Change the phone number of a selected record."); System.out.println("7.Withdraw an amount requested by the record."); System.out.println("8.Add a deposit for a selected record."); System.out.println("9.Quit"); System.out.print("Enter a command from the list above (9 to quit):"); command = sc.nextInt(); sc.nextLine(); switch (command) { case 1: showAllRecord(); break; case 2: showAllRecord(); System.out.print("Enter the First name of the record you want to delete:"); firstName = sc.nextLine(); System.out.print("Now enter Last Name :"); lastName = sc.nextLine(); deleteRecord(firstName, lastName); break; case 3: showAllRecord(); System.out.print("Enter the First name of the record you want to change the First name of:"); firstName = sc.nextLine(); System.out.print("Now Enter New First Name:"); newFirstName = sc.nextLine(); System.out.print("Now enter Last Name :"); lastName = sc.nextLine(); changeFirstName(firstName, lastName, newFirstName); break; case 4: showAllRecord(); System.out.print("Enter the First name of the record you want to change the last name of:"); firstName = sc.nextLine(); System.out.print("Now enter Last Name :"); lastName = sc.nextLine(); System.out.print("Now enter New Last Name :"); newLastName = sc.nextLine(); changeLastName(firstName, lastName, newLastName); break; case 5: System.out.print("Enter First Name :"); firstName = sc.nextLine(); System.out.print("Enter Last Name :"); lastName = sc.nextLine(); System.out.print("Enter Phone Number :"); phoneNumber = sc.nextLine(); System.out.print("Enter Amount :"); String amt = sc.nextLine(); amount = Double.parseDouble(amt.substring(1)); addRecord(firstName, lastName, phoneNumber, amount); break; case 6: System.out.print("Enter the First name of the record you want to change the phone number of:"); firstName = sc.nextLine(); System.out.print("Now enter Last Name :"); lastName = sc.nextLine(); System.out.print("Enter New Phone Number"); phoneNumber = sc.nextLine(); changePhoneNumber(firstName, lastName, phoneNumber); break; case 7: showAllRecord(); System.out.print("Enter the First name of the record you want to withdraw from:"); firstName = sc.nextLine(); System.out.print("Now enter the last name:"); lastName = sc.nextLine(); System.out.print("Enter amount to be withdrawn:"); amount = sc.nextDouble(); withdrawAmount(firstName, lastName, amount); break; case 8: System.out.print("Enter the First name of the record you want to withdraw from:"); firstName = sc.nextLine(); System.out.print("Now enter the last name:"); lastName = sc.nextLine(); System.out.print("Enter amount to be deposit:"); amount = sc.nextDouble(); depositAmount(firstName, lastName, amount); break; case 9: command = 9; } } while (command != 9); } public static void sortList() { int length = customers.size(); for (int i = 0; i