Design an an abstract class named BankAccount to hold the fo
Design an an abstract class named BankAccount to hold the following data for a bank accou Balance Number of deposits this month \"+e); } } }
Solution
import java.util.Scanner; import java.util.Random; import java.lang.Exception; class MyException extends Exception { MyException(String message) { super(message); } } interface Account { void CreateAcc(); void Deposit(); void Withdraw(); } class BankUtilities { int acctype,year=1,ssn=0,accnum; float intr; String name=\"\"; String loc=\"\"; Scanner in = new Scanner(System.in); Random rnd = new Random(); double temp=0.0,bal=0.0; } class Bank extends BankUtilities implements Account { void getInfo() { try { System.out.print(\"Enter Name: \"); name=in.nextLine(); System.out.print(\"Enter SSN: \"); ssn=in.nextInt(); in.nextLine(); System.out.print(\"Enter Location: \"); loc=in.nextLine(); System.out.println(\"Mention account type:\ 1.Savings (7% intr )\\t2.Current (5% intr) \"); acctype=in.nextInt(); switch(acctype) { case 1: System.out.println(\"Enter the initial amount of deposit:\"); temp=in.nextFloat(); if(temp<0) { System.out.println(\"Invalid Amount\ Try again:\ \"); System.out.println(\"Enter the initial amount of deposit:\"); temp=in.nextFloat(); } Deposit(temp); System.out.println(\"Enter noof years:\"); year=in.nextInt(); if(year<=0) { System.out.println(\"Invalid year\ Try again.\"); System.out.println(\"Enter noof years:\"); year=in.nextInt(); } break; case 2: System.out.println(\"Enter the initial amount of deposit:\"); temp=in.nextFloat(); if(temp<0) { System.out.println(\"Invalid Amount\ Try again:\ \"); System.out.println(\"Enter the initial amount of deposit:\"); temp=in.nextFloat(); } Deposit(temp); break; default: System.out.println(\"Invalid Option\"); } //Switch } catch(Exception e) { System.out.println(\"Inbuilt Exception --> \"+e); System.exit(0); } }//getInfo public void CreateAcc() { try { getInfo(); System.out.println(\"\ Account Successfully Created!\"); accnum=rnd.nextInt(1000)+1; System.out.println(\"Hello \"+name+\" your account no is \" +accnum+\".\ \"); } catch(Exception e) { System.out.println(\"Fatal Error\"); } } void Deposit(double temp) // Initial Deposit { try { if(temp>500) { bal+=temp; System.out.println(\"SUCCESSFULLY CREDITED\"); } else { throw new MyException(\"Minimum Deposit Violation\"); } } catch(MyException e) { System.out.println(e.getMessage()); System.out.println(\"TRANSACTION FAILURE\"); System.exit(0); } } public void Deposit() // regular deposit { System.out.println(\"Enter the amount to be deposited :\"); temp=in.nextFloat(); try { if(temp>0) { bal+=temp; System.out.println(\"SUCCESSFULLY CREDITED\"); } else { throw new MyException(\"INVALID AMOUNT EXCEPTION\"); } } catch(MyException e) { System.out.println(e.getMessage()); System.out.println(\"TRANSACTION FAILURE\"); } } public void Withdraw()// regular deposit { System.out.println(\"Enter the amount to be withdrawn :\"); temp=in.nextFloat(); if(temp<=0) { System.out.println(\"Invalid Amount Error.\"); System.exit(0); } try { if(temp