You are to write a program name Bank.java that maintains a list of records conta
ID: 3677256 • Letter: Y
Question
You are to write a program name Bank.java that maintains a list of records containing names and balance of customers. 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:
a Show all records
r Remove the current record
f Change the first name in the current record
l Change the last name in the current record
n Add a new record
d Add a deposit to the current record
w Make a withdrawal from the current record
q Quit
s Select a record from the record list to become the current record
The following example illustrates the behavior of each command (user input is inbold)
c:java Bank [enter]
A Program to keep a Bank Record:
a Show all records
r Remove the current record
f Change the first name in the current record
l Change the last name in the current record
n Add a new record
d Add a deposit to the current record
w Make a withdrawal from the current record
q Quit
s Select a record from the record list to become the current record
Enter a command from the list above (q to quit): a
No records exist!!
a Show all records
r Remove the current record
f Change the first name in the current record
l Change the last name in the current record
n Add a new record
d Add a deposit to the current record
w Make a withdrawal from the current record
q Quit
s Select a record from the record list to become the current record
Enter a command from the list above (q to quit): n
Enter first name: Barry
Enter last name: Drake
Enter the balance amount: 1000
Current record is: Barry Drake $1000.00
a Show all records
r Remove the current record
f Change the first name in the current record
l Change the last name in the current record
n Add a new record
d Add a deposit to the current record
w Make a withdrawal from the current record
q Quit
s Select a record from the record list to become the new current record
Enter a command from the list above (q to quit): n
MENU DISPLAYED AGAIN
Enter a command from the list above (q to quit): a
Enter first name: Ada
Enter last name: Caswell
Current record is: Ada Caswell
MENU DISPLAYED AGAIN
Enter a command from the list above (q to quit): a
First Name Last Name Current balance
------------- ------------- ------------------
Ada Caswell $0.00
Barry Drake $1000.00
MENU DISPLAYED AGAIN
Enter a command from the list above (q to quit): n
Enter first name: Elwood
Enter last name: Havens
Current record is: Elwood Havens
MENU DISPLAYED AGAIN
Enter a command from the list above (q to quit): a
First Name Last Name Current Balance
------------- ------------- ------------------
Ada Caswell $0.00
Barry Drake $1000.00
Elwood Havens $0.00
MENU DISPLAYED AGAIN
Enter a command from the list above (q to quit): f
Enter new first name: Jake
Current record is: Jake Havens
MENU DISPLAYED AGAIN
Enter a command from the list above (q to quit): s
Enter first name: Carl
Enter last name: Patton
No matching record found.
MENU DISPLAYED AGAIN
Enter a command from the list above (q to quit): s
Enter first name: Barry
Enter last name: Drake
Current record is: Barry Drake
MENU DISPLAYED AGAIN
Enter a command from the list above (q to quit): r
Deleted: Barry Drake
MENU DISPLAYED AGAIN
Enter a command from the list above (q to quit): a
First Name Last Name Current Balance
------------- ------------- ------------------
Ada Caswell $0.00
Elwood Havens $0.00
MENU DISPLAYED AGAIN
Enter a command from the list above (q to quit): s
Enter first name: Ada
Enter last name: Caswell
Current record is: Ada Caswell
MENU DISPLAYED AGAIN
Enter a command from the list above (q to quit): d
Enter the deposited amount: 1000.00
Current record is: Ada Caswell with 1000.00 added to deposit
MENU DISPLAYED AGAIN
Enter a command from the list above (q to quit): a
First Name Last Name Current Balance
------------- ------------- ------------------
Ada Caswell $1000.00
Elwood Havens $0.00
MENU DISPLAYED AGAIN
Enter a command from the list above (q to quit): q
The output of your program must match the format illustrated in this example.
Here are some other additional requirements for this program:
After a deletion, there is no record currently selected
Each record (first name, last name and balance) 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.
Explanation / Answer
import java.io.*; class Curr_acct //CURRENT ACCOUNT CLASS { final int max_limit=20; final int min_limit=1; final double min_bal=500; private String name[]=new String[20]; privateint accNo[]=newint[20]; private String accType[]=new String[20]; privatedouble balAmt[]=newdouble[20]; staticint totRec=0; //Intializing Methodpublicvoid initialize() { for(int i=0;imax_limit) { System.out.println(" Sorry we cannot admit you in our bank... "); permit=false; } if(permit = true) //Allows to create new entry { totRec++; // Incrementing Total Record System.out.println(" =====RECORDING NEW ENTRY====="); try{ accNo[totRec]=totRec; //Created AutoNumber to accNo so no invalid id occurs System.out.println("Account Number : "+accNo[totRec]); BufferedReader obj = new BufferedReader(new InputStreamReader(System.in)); System.out.print("Enter Name : "); System.out.flush(); name[totRec]=obj.readLine(); accType[totRec]="Current Account"; System.out.println("Account Type : "+accType[totRec]); do{ System.out.print("Enter Initial Amount to be deposited : "); System.out.flush(); str=obj.readLine(); balAmt[totRec]=Double.parseDouble(str); }while(balAmt[totRec]= min_bal) { balAmt[acno]=checkamt; //Displaying Depsit Details System.out.println(" After Updation..."); System.out.println("Account Number : "+acno); System.out.println("Balance Amount : "+balAmt[acno]+" "); } else { System.out.println(" Your Balance has gone down and so penalty is calculated"); //Bank policy is to charge 20% on total difference of balAmt and min_bal to be maintain penalty=((min_bal - checkamt)*20)/100; balAmt[acno]=balAmt[acno]-(amt+penalty); System.out.println("Now your balance revels : "+balAmt[acno]+" "); } } } catch(Exception e) {} } } class Sav_acct //SAVING ACCOUNT CLASS { final int max_limit=20; final int min_limit=1; final double min_bal=500; private String name[]=new String[20]; privateint accNo[]=newint[20]; private String accType[]=new String[20]; privatedouble balAmt[]=newdouble[20]; staticint totRec=0; //Intializing Methodpublicvoid initialize() { for(int i=0;imax_limit) { System.out.println(" Sorry we cannot admit you in our bank... "); permit=false; } if(permit = true) //Allows to create new entry { totRec++; // Incrementing Total Record System.out.println(" =====RECORDING NEW ENTRY====="); try{ accNo[totRec]=totRec; //Created AutoNumber to accNo so no invalid id occurs System.out.println("Account Number : "+accNo[totRec]); BufferedReader obj = new BufferedReader(new InputStreamReader(System.in)); System.out.print("Enter Name : "); System.out.flush(); name[totRec]=obj.readLine(); accType[totRec]="Saving Account"; System.out.println("Account Type : "+accType[totRec]); do{ System.out.print("Enter Initial Amount to be deposited : "); System.out.flush(); str=obj.readLine(); balAmt[totRec]=Double.parseDouble(str); }while(balAmt[totRec]= min_bal) { balAmt[acno]=checkamt; //Displaying Depsit Details System.out.println(" After Updation..."); System.out.println("Account Number : "+acno); System.out.println("Balance Amount : "+balAmt[acno]+" "); } else { System.out.println(" As per Bank Rule you should maintain minimum balance of Rs 500 "); } } } catch(Exception e) {} } } class Bank_improved { publicstaticvoid main(String args[]) { String str; int choice,check_acct=1,quit=0; choice=0; Curr_acct curr_obj = new Curr_acct(); Sav_acct sav_obj = new Sav_acct(); System.out.println(" =====WELLCOME TO BANK DEMO PROJECT===== "); while( quit!=1) { try{ BufferedReader obj = new BufferedReader(new InputStreamReader(System.in)); System.out.print("Type 1 for Current Account and Any no for Saving Account : "); System.out.flush(); str=obj.readLine(); check_acct=Integer.parseInt(str); } catch(Exception e) {} if(check_acct==1) { do//For Current Account { System.out.println(" Choose Your Choices ..."); System.out.println("1) New Record Entry "); System.out.println("2) Display Record Details "); System.out.println("3) Deposit..."); System.out.println("4) Withdraw..."); System.out.println("5) Quit"); System.out.print("Enter your choice : "); System.out.flush(); try{ BufferedReader obj = new BufferedReader(new InputStreamReader(System.in)); str=obj.readLine(); choice=Integer.parseInt(str); switch(choice) { case 1 : //New Record Entry curr_obj.newEntry(); break; case 2 : //Displaying Record Details curr_obj.display(); break; case 3 : //Deposit... curr_obj.deposit(); break; case 4 : //Withdraw... curr_obj.withdraw(); break; case 5 : System.out.println(" .....Closing Current Account....."); break; default : System.out.println(" Invalid Choice "); } } catch(Exception e) {} }while(choice!=5); } else { do//For Saving Account { System.out.println("Choose Your Choices ..."); System.out.println("1) New Record Entry "); System.out.println("2) Display Record Details "); System.out.println("3) Deposit..."); System.out.println("4) Withdraw..."); System.out.println("5) Quit"); System.out.print("Enter your choice : "); System.out.flush(); try{ BufferedReader obj = new BufferedReader(new InputStreamReader(System.in)); str=obj.readLine(); choice=Integer.parseInt(str); switch(choice) { case 1 : //New Record Entry sav_obj.newEntry(); break; case 2 : //Displaying Record Details sav_obj.display(); break; case 3 : //Deposit... sav_obj.deposit(); break; case 4 : //Withdraw... sav_obj.withdraw(); break; case 5 : System.out.println(" .....Closing Saving Account....."); break; default : System.out.println(" Invalid Choice "); } } catch(Exception e) {} }while(choice!=5); } try{ BufferedReader obj = new BufferedReader(new InputStreamReader(System.in)); System.out.print(" Enter 1 for Exit : "); System.out.flush(); str=obj.readLine(); quit=Integer.parseInt(str); }catch (Exception e){} } } }Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.