Java Code
//FA2019_ArrayBasedStructureDemo_Dawadi import javax.swing.JOptionPane;//displays pane with notice import java.util.ArrayList;//needed to use arrays import java.util.Scanner;//needed to scan user input /** * * @author rozandwd */ public class FA2019_ArrayBasedStructureDemo_Dawadi { ArrayList<CheckingsAccount_Dawadi> c = new ArrayList<CheckingsAccount_Dawadi>(); ArrayList<SavingsAccount_Dawadi> s = new ArrayList<SavingsAccount_Dawadi>(); Scanner sc=new Scanner(System.in); public void insert() { int choice; String acc,nam,test; double bal,fee,inter; System.out.println("Please enter the type of account:"); System.out.println("1. Checking Account:"); System.out.println("2. Saving Account:"); choice=sc.nextInt();//selects user input and acts accordingly if(choice==1) { for ( int i=0; i<3; i++ )//runs the loop 3 times as required { System.out.println("Please enter your Account number:"); acc=sc.next(); sc.nextLine(); System.out.println("Please enter your Name:"); nam=sc.next(); System.out.println("Please enter the balance:"); bal=sc.nextDouble(); System.out.println("Please enter the fee:"); fee=sc.nextDouble(); if (bal>=0){ c.add(new CheckingsAccount_Dawadi(acc,nam,bal,fee)); System.out.println("Insert Account Success"); showBox("Insert success!"); }else System.out.println("Insert Account failed"); showBox("Insert Failed!"); } } else if(choice==2) { System.out.println("Please enter your Account number:"); acc=sc.next(); sc.nextLine(); System.out.println("Please enter your Name:"); nam=sc.nextLine(); System.out.println("Please enter the balance:"); bal=sc.nextDouble(); System.out.println("Please enter the interest rate:"); inter=sc.nextDouble(); if (bal>=0){ s.add(new SavingsAccount_Dawadi(acc,nam,bal,inter)); System.out.println("Insert Account Success"); } else System.out.println("Insert Account failed"); } else { System.out.println("invalid choice"); insert(); } } public void encap() { int choice; String acc,nam; double bal,fee,inter; System.out.println("Please enter the type of account:"); System.out.println("1. Checking Account:"); System.out.println("2. Saving Account:"); choice=sc.nextInt(); if(choice==1) { System.out.println("Please enter your Account number:"); acc=sc.next(); sc.nextLine(); System.out.println("Please enter your Name:"); nam=sc.nextLine(); System.out.println("Please enter the balance:"); bal=sc.nextDouble(); System.out.println("Please enter the fee:"); fee=sc.nextDouble(); for(CheckingsAccount_Dawadi che:c) { if(che.accNumber==acc) { che.serviceFee=fee; CheckingsAccount_Dawadi copy = new CheckingsAccount_Dawadi(); copy=che; if(copy.serviceFee==fee) { System.out.println("Unsorted Optimized Array is not encapsulated"); } else System.out.println("Unsorted Optimized Array is encapsulated"); } } } else if(choice==2) { System.out.println("Please enter your Account number:"); acc=sc.next(); sc.nextLine(); System.out.println("Please enter your Name:"); nam=sc.nextLine(); System.out.println("Please enter the balance:"); bal=sc.nextDouble(); System.out.println("Please enter the interest rate:"); inter=sc.nextDouble(); for(SavingsAccount_Dawadi sav:s) { if(sav.accNumber==acc) { sav.balance=bal; SavingsAccount_Dawadi copy = new SavingsAccount_Dawadi(); copy=sav; if(copy.interestRate==inter) { System.out.println("Unsorted Optimized Array is not encapsulated"); } else System.out.println("Unsorted Optimized Array is encapsulated"); } } } else { System.out.println("invalid choice"); encap(); } } public void update() { int choice; String acc,nam; double bal,fee,inter; System.out.println("Please enter the type of account:"); System.out.println("1. Checking Account:"); System.out.println("2. Saving Account:"); choice=sc.nextInt(); if(choice==1) { System.out.println("Please enter your Account number:"); acc=sc.next(); sc.nextLine(); System.out.println("Please enter your Name:"); nam=sc.nextLine(); System.out.println("Please enter the balance:"); bal=sc.nextDouble(); System.out.println("Please enter the fee:"); fee=sc.nextDouble(); for(CheckingsAccount_Dawadi che:c) { if(che.accNumber==acc) { che.serviceFee=fee; } } System.out.println("Update Successfully"); } else if(choice==2) { System.out.println("Please enter your Account number:"); acc=sc.next(); sc.nextLine(); System.out.println("Please enter your Name:"); nam=sc.nextLine(); System.out.println("Please enter the balance:"); bal=sc.nextDouble(); System.out.println("Please enter the interest rate:"); inter=sc.nextDouble(); for(SavingsAccount_Dawadi sav:s) { if(sav.accNumber==acc) { sav.balance=bal; } } System.out.println("Successfully updated"); } else { System.out.println("Update failed"); update(); } } public void remove_acc() { String acc; System.out.println("Please enter the account number of the account that you want to remove:"); acc=sc.next(); sc.nextLine(); for(CheckingsAccount_Dawadi che:c) { if(che.accNumber.equals(acc)) { c.remove(che); System.out.println("Delete successfully"); break; } } for(SavingsAccount_Dawadi sav:s) { if(sav.accNumber.equals(acc)) { s.remove(sav); System.out.println("Delete failed"); break; } } } public void show() { System.out.println("Checking Account"); System.out.println("#######################################"); for(CheckingsAccount_Dawadi che:c) { che.printStatement(); System.out.println(" "); } System.out.println("***************************************"); System.out.println("***************************************"); System.out.println(" "); System.out.println("Savings Account"); System.out.println("***************************************"); for(SavingsAccount_Dawadi sav:s) { sav.printStatement(); System.out.println(" "); } } private void showBox(String insert_success) { //To change body of generated methods, choose Tools | Templates. } }