// Assignment #: 5
// Name: Vivian
// StudentID: 1209879837
// Lecture: TTh 4:30PM
// Description: CheckingAccount is subclass of BankAccount class, so it has
attributes inherited from BankAccount but also with attributes
// specific to a Checking type bank account.
public class CheckingAccount
{
private int overdraftFeePennies;//The overdraft fee of the checking
account
public CheckingAccount (int balance, double interestRate, String
accountNum, int overdraftFeeInPennies)//parent class, BankAccount, constructor
called using first three parameters to initialize its variables. Also
initializes overDraftFeePennies to fourth parameter
{
super (balance, interestRate, accountNum);
overdraftFeePennies = overdraftFeeInPennies;
}
public int getOverdraftFee ()//returns overdraft fee in pennies
{
return overdraftFeePennies;
}
public void setOverdraftFee (int fee)//change overdraft fee
{
overdraftFeePennies = fee;
}
public boolean debit (int amountPennies)
{
if (balanceInPennies-amountPennies<0){//check if account will
overdraft
balanceInPennies -= amountPennies;//subtract debit amount
balancceInPennies -= overdraftFeePennies;//subtract also
overdraft fee
return false;//returns false to signify overdraft
}else{
balanceInPennies -= amountPennies;//subtracts debit amount
return true;//returns true to signify siccessful
withdrawal/charge with no overdraft
}
}
public void applyInterest ()
{
double interestAmount = (double)(balanceInPennies);
interestAmount = interestAmount/100;
interestAmount = interestAmount*interestRate;
interestAmount = interestAmount*100;
balanceInPennies -= (int) interestAmount;
}
public String toString ()//displays info of checking account also
containing info from inherited class BankAccount toString method string
{
double oddfee = (double)(overdraftFeePennies);
oddfee = oddfee/100;
return ("\nAccount type\t:\tChecking"+super.toString()+
"Overdraft fee\t:\t"+oddfee"\n\n");
}
}
Powered by TCPDF (www.tcpdf.org)