create a class called BankAccount The BankAccount class shou
create a class called BankAccount. The BankAccount class should contain a String to store the customer name and a double to store the account balance. The BankAccount class (which is different from the Module 3 BankAccount class), should have two constructors, as follows:
public BankAccount(String name, double balance)
throws NegativeAmountException
{
// set name and balance
// make sure balance is not negative
// throw exception if balance is negative
}
public BankAccount(String name)
throws NegativeAmountException
{
// set name and use 0 balance
}
As can be seen, the first constructor throws a NegativeAmountException if the balance being used to create the bank account is negative. You will have to create this exception class yourself.
The BankAccount class should also contain methods to make a deposit, make a withdrawal, get the current balance, and print a bank account statement. The interfaces for these methods should appear as follows:
// update balance by adding deposit amount
// make sure deposit amount is not negative
// throw exception if deposit is negative
public void deposit(double amount) throws NegativeAmountException
// update balance by subtracting withdrawal amount
// throw exception if funds are not sufficient
// make sure withdrawal amount is not negative
// throw NegativeAmountException if amount is negative
// throw InsufficientFundsException if balance < amount
public void withdraw(double amount)
throws InsufficientFundsException, NegativeAmountException
// return current balance
public double getBalance()
// print bank statement including customer name
// and current account balance
public void printStatement();
Use the BankAccount class as the superclass for a SavingsAccount class. In addition to the behaviors of a BankAccount, a SavingsAccount also accumulates interest; therefore, the SavingsAccount class contains a double that is populated with the current interest rate. In addition to its constructors (you decide what the constructors should be), the SavingsAccount class should contain the following methods:
// post monthly interest by multiplying current balance
// by current interest rate divided by 12 and then adding
// result to balance by making deposit
public void postInterest()
// print bank statement including customer name
// and current account balance (use printStatement from
// the BankAccount superclass)
// following this also print current interest rate
public void printStatement()
Once these two classes are completed, create a driver class called FinalExam containing a main method that tests the SavingsAccount class. Within the driver test class, create a SavingsAccount object and then use it to make deposits and withdrawals, and to post the monthly interest.
Solution
class bankaccount
{
public BankAccount(String name, double balance)
throws NegativeAmountException
{
system.out.println(\"enter balance\");
if(n<0)
{
sstem.out.println(\"Please enter positive value of balance\");
}
}
// throw exception if balance is negative
}
public BankAccount(String name)
throws NegativeAmountException
{
// set name and use 0 balance
}
public BankAccount(String name)
throws NegativeAmountException
{
name=\"Stephen\";
float balance=0.0;
}
public void deposit(double amount) throws NegativeAmountException
float withdrawl;
float amount=balance-withdrawl;
if(amount<0)
{
system.out.println(\"please maintain sufficient funds\");
}
if(withdrawl<0||withdrawl>amount)
{
System.out.println(\"Please enter valid value \");
}
public void withdraw(double amount)
throws InsufficientFundsException, NegativeAmountException{
public float currentbalance,deposit;
newbalance=currentbalance+deposit;
if(deposit <0)
{ system.out.println(\"please deposit positive amount\");}
return currentbalance;
}
public double getBalance()
int n;
system.out.println(\"enter number of customers for whcih you want bank statement \");
}
}


