import javautilDate import javautilScanner public class Acco
 import java.util.Date;
 import java.util.Scanner;
public class Account {
 protected int accountID;
 protected double balance;
 protected double annualInterestRate;
 protected Date dateCreated;
   
 public Account() {
 accountID = 0;
 balance = 0;
 annualInterestRate = 0;
 dateCreated = new Date();
 }
   
 public Account(int accountID, double balance, double annualInterestRate) {
 this.accountID = accountID;
 this.balance = balance;
 this.annualInterestRate = annualInterestRate;
 dateCreated = new Date();
 }
   
 /**
 *
 * @return the Account\'s ID
 */
 public int getAccountID() {
 return accountID;
 }
   
 /**
 *
 * @param accountID the ID the user wants the accountID changed to.
 */
 public void setAccountID(int accountID) {
 this.accountID = accountID;
 }
   
 /**
 *
 * @return the account balance.
 */
 public double getBalance() {
 return balance;
 }
   
 /**
 *
 * @param balance the amount that the user wants the balance
 * changed to.
 */
 public void setBalance(double amount) {
 this.balance = amount;
 }
   
 /**
 *
 * @return the annual interest rate.
 */
 public double getAnnualInterestRate() {
 return annualInterestRate;
 }
 /**
 *
 * @param annualInterestRate interest rate to change to.
 */
 public void setAnnualInterestRate(double annualInterestRate) {
 this.annualInterestRate = annualInterestRate;
 }
   
 /**
 *
 * @return the date the account was created.
 */
 public Date getDateCreated() {
 return dateCreated;
 }
 /**
 *
 * @return monthly interest rate calculated from the annual interest
 * and the balance.
 */
 public double getMonthlyInterest() {
 return (annualInterestRate*balance)/12;
 }
 /**
 *
 * @param amount amount to be withdrawn
 */
 public void withdraw(double amount) {
 balance -= amount;
 }
 /**
 *
 * @param amount amount to be deposited
 */
 public void deposit(double amount) {
 balance += amount;
 }
 /**
 *
 * @param amount amount to be deposited.
 */
 public void deposit(int amount) {
 balance += (double)amount;
 }
   
 /**
 * @return string representation of the account.
 */
 public String toString() {
 return \"Account ID:\\t\\t\\t\"
 + accountID
 + \"\ Balance:\\t\\t\\t$\"
 + String.format(\"%.02f\", balance)
 + \"\ Monthly Interest Earned:\\t$\"
 + String.format(\"%.02f\", getMonthlyInterest())
 + \"\ Date Created:\\t\\t\\t\"
 + getDateCreated();
 }
public class Checking extends Account {
 private final double MAX_OVERDRAFT = -5000.00;
   
 public Checking() {
 // Auto-generated constructor stub
 super();
 }
public Checking(int accountID, double balance, double annualInterestRate) {
 super(accountID, balance, annualInterestRate);
 // Auto-generated constructor stub
 }
   
 /**
 * @param amount amount to be withdrawn from the account.
 */
 @Override
 public void withdraw(double amount) {
 if(amount > 0) {
 if(balance-amount < MAX_OVERDRAFT){
 System.out.println(\"Account has reached it\'s withdrawal limit.\");
 }
 else
 balance -= amount;
 }
 else
 System.out.println(\"Cannot withdraw a negative amount.\");
 }
public class Savings extends Account {
public Savings() {
 // Auto-generated constructor stub
 }
   
 public Savings(int accountID, double balance, double annualInterestRate) {
 super(accountID, balance, annualInterestRate);
 // Auto-generated constructor stub
 }
   
 /**
 * @param amount amount to be withdrawn
 */
 @Override
 public void withdraw(double amount) {
 if(amount > 0) {
 if (balance-amount < 0) {
 System.out.println(\"Account has reached it\'s withdrawal limit.\");
 }
 else
 balance -= amount;
 }
 else
 System.out.println(\"Cannot withdraw a negative amount!\");
 }
public class TestAccount {
public static void main(String[] args) {
 // T Auto-generated method stub
 Scanner kb = new Scanner(System.in);
   
 //user variables used to create Accounts
 int ID;
 double bal, interest;
   
 //Getting the parameter values from the user for the
 //Savings Account
 System.out.print(\"Enter an ID for the savings account: \");
 ID = kb.nextInt();
 System.out.print(\"Enter the starting balance for the account: \");
 bal = kb.nextDouble();
 System.out.print(\"Enter the annual interest rate for the account: \");
 interest = kb.nextDouble();
   
 //Creating the savings
 Savings mySavings = new Savings(ID, bal, interest);
   
 //Getting the parameter values from the user for the
 //Checking Account
 System.out.print(\"Enter an ID for the checking account: \");
 ID = kb.nextInt();
 System.out.print(\"Enter the starting balance for the account: \");
 bal = kb.nextDouble();
 System.out.print(\"Enter the annual interest rate for the account: \");
 interest = kb.nextDouble();
   
 //Creating the checking
 Checking myChecking = new Checking(ID, bal, interest);
   
 //testing the savings withdraw
 System.out.print(\"How much should be withdrawn from the savings: \");
 mySavings.withdraw(kb.nextDouble());
   
 //testing the savings deposit
 System.out.print(\"How much should be deposited into the savings: \");
 mySavings.deposit(kb.nextDouble());
   
 //testing the checking withdraw
 System.out.print(\"How much should be withdrawn from the checking: \");
 myChecking.withdraw(kb.nextDouble());
   
 //testing the checking deposit
 System.out.print(\"How much should be deposited into the checking: \");
 myChecking.deposit(kb.nextDouble());
   
 //printing the two accounts.
 System.out.println(mySavings);
 System.out.println();
 System.out.println(myChecking);
   
 }
}
 }
 }
 }
Solution
mport java.io.*;
class BankWork
{
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;
//constructor
BankWork()
{
for(int i=0;i<max_limit;i++)
{
name[i]=\"\";
accNo[i]=0;
accType[i]=\"\";
balAmt[i]=0.0;
}
}
//TO ADD NEW RECORDpublicvoid newEntry()
{
String str;
int acno;
double amt;
boolean permit;
permit=true;
if (totRec>max_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();
System.out.print(\"Enter Account Type : \");
System.out.flush();
accType[totRec]=obj.readLine();
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); //Validation that minimun amount must be 500
System.out.println(\"\ \ \ \");
}
catch(Exception e)
{}
}
}
//TO DISPLAY DETAILS OF RECORDpublicvoid display()
{
String str;
int acno=0;
boolean valid=true;
System.out.println(\"\ \ =====DISPLAYING DETAILS OF CUSTOMER=====\ \");
try{
BufferedReader obj = new BufferedReader(new InputStreamReader(System.in));
System.out.print(\"Enter Account number : \");
System.out.flush();
str=obj.readLine();
acno=Integer.parseInt(str);
if (acno<min_limit || acno>totRec) //To check whether accNo is valid or Not
{
System.out.println(\"\ \ \ Invalid Account Number \ \ \");
valid=false;
}
if (valid==true)
{
System.out.println(\"\ \ Account Number : \"+accNo[acno]);
System.out.println(\"Name : \"+name[acno]);
System.out.println(\"Account Type : \"+accType[acno]);
System.out.println(\"Balance Amount : \"+balAmt[acno]+\"\ \ \ \");
}
}
catch(Exception e)
{}
}
//TO DEPOSIT AN AMOUNTpublicvoid deposit()
{
String str;
double amt;
int acno;
boolean valid=true;
System.out.println(\"\ \ \ =====DEPOSIT AMOUNT=====\");
try{
//Reading deposit value
BufferedReader obj = new BufferedReader(new InputStreamReader(System.in));
System.out.print(\"Enter Account No : \");
System.out.flush();
str=obj.readLine();
acno=Integer.parseInt(str);
if (acno<min_limit || acno>totRec) //To check whether accNo is valid or Not
{
System.out.println(\"\ \ \ Invalid Account Number \ \ \");
valid=false;
}
if (valid==true)
{
System.out.print(\"Enter Amount you want to Deposit : \");
System.out.flush();
str=obj.readLine();
amt=Double.parseDouble(str);
balAmt[acno]=balAmt[acno]+amt;
//Displaying Depsit Details
System.out.println(\"\ After Updation...\");
System.out.println(\"Account Number : \"+acno);
System.out.println(\"Balance Amount : \"+balAmt[acno]+\"\ \ \ \");
}
}
catch(Exception e)
{}
}
//TO WITHDRAW BALANCEpublicvoid withdraw()
{
String str;
double amt,checkamt;
int acno;
boolean valid=true;
System.out.println(\"\ \ \ =====WITHDRAW AMOUNT=====\");
try{
//Reading deposit value
BufferedReader obj = new BufferedReader(new InputStreamReader(System.in));
System.out.print(\"Enter Account No : \");
System.out.flush();
str=obj.readLine();
acno=Integer.parseInt(str);
if (acno<min_limit || acno>totRec) //To check whether accNo is valid or Not
{
System.out.println(\"\ \ \ Invalid Account Number \ \ \");
valid=false;
}
if (valid==true)
{
System.out.println(\"Balance is : \"+balAmt[acno]);
System.out.print(\"Enter Amount you want to withdraw : \");
System.out.flush();
str=obj.readLine();
amt=Double.parseDouble(str);
checkamt=balAmt[acno]-amt;
if(checkamt >= 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
{
publicstaticvoid main(String args[])
{
String str;
int choice;
choice=0;
BankWork BW_obj = new BankWork();
do
{
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) Exit\");
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
BW_obj.newEntry();
break;
case 2 : //Displaying Record Details
BW_obj.display();
break;
case 3 : //Deposit...
BW_obj.deposit();
break;
case 4 : //Withdraw...
BW_obj.withdraw();
break;
case 5 : System.out.println(\"\ \ .....THANKS FOR VISITING.....\");
break;
default : System.out.println(\"\ Invalid Choice \ \ \");
}
}
catch(Exception e)
{}
}while(choice!=5);
}
}











