This is the first part of a 2 part project.
Person Class
Constructor
- public Person( String _name, int _age)
instance Variables
- private String name
- private int age
Methods
- public String getName()
- public int compareTo(Person other) { return this.age - other.age; }
Account – Abstract Super Class
Static Variable(s)
- private static int nextAccountNum
- private static int parentCompanyCode = 12810 ;
Constructor
- public Account( double_balance, Person _owner)
instance Variables
- private int accountNumber
- protected double balance
- protected ArrayList<Person> owners
Methods
- public static int getParentCode()
- public int getAccountNumber()
- public void deposit(double amount)
- public double getCurrentBalance()
- public abstract boolean withdraw(double amount)
- public boolean equals(Account other) // are the unique account numbers equals ?
- public String toString()
- public int comparesTo(Account other) { return this.accountNumber- other.accountNumber } (Note that this method has an ‘s‘ )
- public void addOwner(Person p) //adds P to the ArrayList of owners
- public ArrayList<Person> getOwners() // returns the ArrayList of owners
- public Person remove( Person p) // this emulates the ArrayList’s remove() method (link) . Remember that that method removes the object and then returns the removed object. In this case, you should remove Person P from the ArrayList of owners
- CheckingAccount extends Account
- This class has to do certain things. You can decide the best way to do it. This class should have a way to
- attempt to withdraw money by writing a check
- public void writeCheck(double amount)
-
public void cancelCheck(int checkNumber)
- be able to cancel checks and keep track of the check numbers that have been cancelled
- when a check is cancelled the amount associated with that check is returned back to the balance
- One solution
- every time you write a check, you need a new check “#” (static variable like an id)
- writeCheck( double amount) - > tries to call this.withdraw(double amount) as long as the balance is enough and records a new check number by adding it to an ArrayList<Integer> that stores the check numbers of cancelled checks. It would also need a parallel ArrayList<Double> to store balances (in case the check is cancelled and the amount is refunded to the balance)
SavingsAccount extends Account
- instance variables
- private double interestRate
- private ArrayList<Double> dailyBalances
static variables
- public static final int MINIMUM_BALANCE=100; // this is the absolute minimum amount of money that must always be in the account
- methods
- public boolean withdraw(double amount) //@override the withdraw() method to ensure that currentBalance the never gets below MINIMUM_BALANCE
- public void recordDailyBalance() // @ record current day’s balance by storing current balance.
- public double projectBalance(double timeInYears) // use the compound interest formula . Assume that the bank compounds the balance monthly. To learn more about how compound interest really works, click here .
- public void updateInterestPayment() // @ once a month update account based on average daily balances and interest rate
CertificateOfDeposit extends SavingsAccount
instance Variables
- public static final double EARLY_WITHDRAW_PENALTY= 200 .
Methods
- public boolean withdraw(double amount , boolean isEarly ) //@override the withdraw() and applies penalty to balance
When you are done, you can begin the Bank project .