Design a class named BankAccount containing the
following data field and methods.
• One double data field named balance with default
values 0.0 to denote the balance of the account.
• A no-arg constructor that creates a default bank
account.
• A constructor that creates a bank account with the
specified balance.
throw an IllegalArgumentException when
constructing an account with a negative balance
• The accessor method for the data field.
• A method named deposit(double amount) that deposits
money into the bank account.
throw an IllegalArgumentException when deposit a
negative amount into an account
• A method named withdraw(double amount) that withdraws
the money from the bank account.
throw an IllegalArgumentException when
withdrawing a negative amount from an account
define the exception class
InsufficientFundsException
throw an InsufficientFundsException
when the balance is less than the
withdrawal amount.
• A method transfer(double amount, BankAccount other)
that transfer money from the bank account to another
account.
• A method named toString() that returns a string
description for the account.
Design two classes CheckingAccount and SavingAccount which are
derived from the
class BankAccount.
• CheckingAccount will charge transaction fees. Each month there
are 5 free
transactions. $3 will be deducted from the checking account for
every extra
transaction. (Hint: You need to add a method to deduct the fees
from the
checking account if there are more than 5 tractions in a month. You
need to
modify the deposit and withdrawal method as well, and you need to
add an
instance field to remember the number of transactions. You may need
to define
two constants, one for number of allowed free transactions and the
other for fee
per extra transaction.)
• SavingAccount will earn income at fixed interest rate. (Hint: You
need to add a
method to add interest each month. Also you need to add an instance
field for
interest rate.)
Write your test program to create objects and test all
the methods. Your test program
should cause all three exceptions to occur and catches them
all.
//driver class
public class Driver{
public static void main(String
[]args){
//declare req
variables
//create a
savings acct object
try
{
BankAccount accounts1=new BankAccount();
System.out.print("\n********Bank Account********");
accounts1=new BankAccount();
//uncomment this step for throwing negatuve amount exception
//accounts1.deposit(-1);
accounts1.deposit(1234);
System.out.println(accounts1);
System.out.println("******************************");
System.out.print("\n*********Savings Account*******");
//create a sacings account object
SavingsAccount accounts2 =new SavingsAccount (60000,21);
System.out.println(accounts2);
accounts2.deposit(21000);
//uncomment this step to throw insuffieict funds exception
// accounts2.withdraw(1000000);
System.out.println("Balance before interest cal:"
+accounts2.getBalance());
accounts2.postInterest();
System.out.println("Balance after interest cal:"
+accounts2.getBalance());
System.out.println("*********************************");
System.out.print("\n*********Checking Account*******");
//create a checking account obejct
CheckingAccount accounts3 =new CheckingAccount (60000,2);
accounts3.deposit(1000);
accounts3.deposit(1000);
accounts3.withdraw(1000);
//unccooment to get negaive amount withdrawn
// accounts3.withdraw(-12);
System.out.println(accounts3);
System.out.println("Balance :" +accounts3.getBalance());
accounts3.withdraw(1000);
System.out.println("After crosing 5 transactions");
System.out.println("Balance :" +accounts3.getBalance());
System.out.println("**********************************");
}
catch(IllegalArgumentException e)
{
System.out.println(e);
}
catch(InsufficientFundsException e)
{
System.out.println(e);
}
catch(Exception
e)
{
System.out.println(e);
}
}
}
class InsufficientFundsException extends Exception{
InsufficientFundsException(String s){
super(s);
}
}
class BankAccount
{
double balance;
public BankAccount()
{
balance=0;
}
public BankAccount(double balance)throws
IllegalArgumentException
{
// set name and
balance
// make sure balance is
not negative
// throw exception if
balance is negative
if(balance<0)
throw new
IllegalArgumentException ("Balance cant'e be negative");
else
this.balance=balance;
}
// 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
IllegalArgumentException
{
if(amount<0)
throw new
IllegalArgumentException ("Negative amount can't be
deposited");
else
balance+=amount;
}
// 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, IllegalArgumentException
{
if(amount<0)
throw new
IllegalArgumentException ("Negative amount can't be
withdrawn");
else
if(amount>balance)
throw new
InsufficientFundsException("No sufficient funds");
else
balance-=amount;
}
// return current balance
public double getBalance()
{
return
balance;
}
//transfer
public void transfer(double amount,
BankAccount other) throws InsufficientFundsException,
IllegalArgumentException
{
this.withdraw(amount);
other.deposit(amount);
}
// print bank statement including customer
name
// and current account balance
public String toString()
{
return "\nBalance:
"+balance;
}
}
class CheckingAccount extends BankAccount
{
int noOfTransactions;
final int FREETRANS=5;
final int FEE=3;
public CheckingAccount(double balance,int
noOfTransactions) throws IllegalArgumentException
{
// set name and
balance
// throw exception if
balance is negative
super(balance);
this.noOfTransactions=noOfTransactions;
}
public CheckingAccount()
{
// set name and
balance
// throw exception if
balance is negative
super(0);
this.noOfTransactions=0;
}
public void deductFee()
{
if(noOfTransactions>FREETRANS)
balance-=5;
}
// 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
IllegalArgumentException
{
if(amount<0)
throw new
IllegalArgumentException ("Negative amount can't be
deposited");
else
balance+=amount;
noOfTransactions++;
deductFee();
}
// 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, IllegalArgumentException
{
if(amount<0)
throw new
IllegalArgumentException ("Negative amount can't be
withdrawn");
else
if(amount>balance)
throw new
InsufficientFundsException("No sufficient funds");
else
balance-=amount;
noOfTransactions++;
deductFee();
}
// print bank statement including customer
name
// and current account balance (use
printStatement from
// the BankAccount superclass)
// following this also print current interest
rate
public String toString()
{
return
super.toString()+"\nNo Of Transactions: "+noOfTransactions;
}
}
class SavingsAccount extends BankAccount
{
double interestRate;
public SavingsAccount(double balance,double
interestRate) throws IllegalArgumentException
{
// set name and
balance
// throw exception if
balance is negative
super(balance);
this.interestRate=interestRate;
}
public SavingsAccount()
{
// set name and
balance
// throw exception if
balance is negative
super(0);
this.interestRate=0;
}
// 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()
{
balance+=(getBalance()*interestRate)/12;
}
// print bank statement including customer
name
// and current account balance (use
printStatement from
// the BankAccount superclass)
// following this also print current interest
rate
public String toString()
{
return
super.toString()+"\nInterest Rate: "+interestRate;
}
}
Design a class named BankAccount containing the following data field and methods. • One double data...
In this, you will create a bank account management system according to the following specifications: BankAccount Abstract Class contains the following constructors and functions: BankAccount(name, balance): a constructor that creates a new account with a name and starting balance. getBalance(): a function that returns the balance of a specific account. deposit(amount): abstract function to be implemented in both Checking and SavingAccount classes. withdraw(amount): abstract function to be implemented in both Checking and SavingAccount classes. messageTo Client (message): used to print...
TASK 1 Create a new class called CheckingAccount that extends BankAccount. It should contain a static constant FEE that represents the cost of clearing onecheck. Set it equal to 15 cents. Write a constructor that takes a name and an initial amount as parameters. Itshould call the constructor for the superclass. It should initializeaccountNumber to be the current value in accountNumber concatenatedwith -10 (All checking accounts at this bank are identified by the extension -10). There can be only one...
C++ Please create the class named BankAccount with the following properties below: // The BankAccount class sets up a clients account (name & ID), keeps track of a user's available balance. // It also keeps track of how many transactions (deposits and/or withdrawals) are made. public class BankAccount { Private String name private String id; private double balance; private int numTransactions; // Please define method definitions for Accessors and Mutator functions below Private member variables string getName(); // No set...
Now create another class named SavingsAccount. This should be a subclass of BankAccount. A SavingsAccount should have an interest rate that is specified in its constructor. Furthermore, there should be a method, addInterest, that deposits interest into account, based on the account balance and interest rate. Create another subclass of BankAccount named CheckingAccount. A CheckingAccount should keep track of the number of transactions made (deposits and withdrawals). Name this field transactionCount. Also, the set fee for transactions is three dollars,...
Design a class named BankAccount that contains: 1. A private int data field named accountId for the account. 2. A private double data field named accountBalance for the account (default 0). 3. A private double data field named annualInterestRate that stores the current interest rate (default 0). Assume all accounts have the same interest rate. 4. A private Date data field named dateCreated that stores the date when the account was created. 5. A private int data field named numberOfDeposits...
Implement a class Portfolio. This class has two objects, checking and savings, of the type BankAccount. Implement four methods: • public void deposit(double amount, String account) • public void withdraw(double amount, String account) • public void transfer(double amount, String account) • public double getBalance(String account) Here the account string is "S" or "C". For the deposit or withdrawal, it indicates which account is affected. For a transfer, it indicates the account from which the money is taken; the money is...
C++ Design a class bankAccount that defines a bank account as an ADT and implements the basic properties of a bank account. The program will be an interactive, menu-driven program. a. Each object of the class bankAccount will hold the following information about an account: account holder’s name account number balance interest rate The data members MUST be private. Create an array of the bankAccount class that can hold up to 20 class objects. b. Include the member functions to...
java code ============= public class BankAccount { private String accountID; private double balance; /** Constructs a bank account with a zero balance @param accountID - ID of the Account */ public BankAccount(String accountID) { balance = 0; this.accountID = accountID; } /** Constructs a bank account with a given balance @param initialBalance the initial balance @param accountID - ID of the Account */ public BankAccount(double initialBalance, String accountID) { this.accountID = accountID; balance = initialBalance; } /** * Returns the...
java code ========= public class BankAccount { private String accountID; private double balance; /** Constructs a bank account with a zero balance @param accountID - ID of the Account */ public BankAccount(String accountID) { balance = 0; this.accountID = accountID; } /** Constructs a bank account with a given balance @param initialBalance the initial balance @param accountID - ID of the Account */ public BankAccount(double initialBalance, String accountID) { this.accountID = accountID; balance = initialBalance; } /** * Returns the...
(The Account class) Design a class named Account that contains: A private int data field named id for the account (default 0). A private double data field named balance for the account (default 0). A private double data field named annualInterestRate that stores the current interest rate (default 0). Assume all accounts have the same interest rate. A private Date data field named dateCreated that stores the date when the account was created. A no-arg constructor that creates a default...