Question: Use the Account and CDAccount classes you created from Assignment 6 (Class Inheritance) Add an overridden equals(Object) method in Account class - if two Account

  • Use the Account and CDAccount classes you created from Assignment 6 (Class Inheritance)
  • Add an overridden equals(Object) method in Account class - if two Account objects with the same ID number return true.
  • Create 100 Account or CDAccount objects randomly, and store in an Account ArrayList. (Account ID from 1001~1100 and generate the initial balance and CDAccount period randomly)
  • Call java.util.Collections.shuffle(ArrayList) to mix up the order of objects in the Account ArrayList.

  • Prompt (console screen or GUI) to the user to provide account numbers and search for the specific objects from the Account ArrayList(Refer to the sample output). ** DON'T use a for-loop to search for the object with matched account id, instead, using contains() or indexof() methods from the ArrayList to find the matched object.
  • For Account objects, print out the account ID and balance (use getID() and getBalance() methods); for CDAccount objects, print out the account number, account type, and mature balance (use getMatureBalance()); for account number cant be found, print out The Account Number doesnt existed!!

** It is NOT allowed to call toString() method to display the account information. You need to use instanceof operator to check the type of account before invoking the corresponding methods to display the account information.

//Account Code

package Module4;

import java.util.Date;

public class Account {

private int id = 0;

private double balance = 0;

private double annualInterestRate = 0;

private Date dateCreated = new Date();

// constructor with all parameters

public Account(int id, double balance, double annualInterestRate, Date dateCreated) {

this.id = id;

this.balance = balance;

this.annualInterestRate = annualInterestRate;

this.dateCreated = dateCreated;

}

// default constructor

public Account() {

}

// getter and setter methods

public int getId() {

return id;

}

public void setId(int id) {

this.id = id;

}

public double getBalance() {

return balance;

}

public void setBalance(double balance) {

this.balance = balance;

}

public double getAnnualInterestRate() {

return annualInterestRate;

}

public void setAnnualInterestRate(double annualInterestRate) {

this.annualInterestRate = annualInterestRate;

}

public Date getDateCreated() {

return dateCreated;

}

public void setDateCreated(Date dateCreated) {

this.dateCreated = dateCreated;

}

// calculate monthly interest rate

public double getMonthlyInterestRate() {

return Math.round(((this.annualInterestRate / 12) * 100.0) / 100.0);

}

// calculate monthly interest

public double getMonthlyInterest() {

return (balance * this.getAnnualInterestRate()) / 100;

}

// withdraw amount if amount is less then balance

public void withdraw(double amount) {

if (amount

this.setBalance(balance - amount);

}

}

// deposit account if amount > 0

public void deposit(double amount) {

if (amount > 0) {

this.setBalance(balance + amount);

}

}

}

//CD Account Code

package Module4;

import java.lang.Math;

import java.util.Date;

public class CDAccount extends Account {

private int duration;

private double CDannualInterestRate;

CDAccount(){

}

CDAccount(int id,double balance,int duration){

super.setId(id);

super.setBalance(balance);

this.duration = duration;

super.setDateCreated(new Date());

super.setAnnualInterestRate(5.50);

}

public void setDuration(int duration) {

this.duration = duration;

}

public int getDuration() {

return this.duration;

}

public double getMatureBalance() {

double matureBalance = 0;

matureBalance = super.getBalance() * Math.pow((1+super.getMonthlyInterestRate()),this.duration);

return matureBalance;

}

public void setCDAnnualInterestRate(double CDannualInterestRate) {

this.CDannualInterestRate = CDannualInterestRate;

}

public double getCDAnnualInterestRate() {

return super.getAnnualInterestRate();

}

public double getMonthlyInterestRate() {

return super.getMonthlyInterestRate();

}

public double getMonthlyInterest() {

return super.getMonthlyInterest();

}

public final void withdraw(double num) {

System.out.println("A CD Account can't withdraw any cash. You need to close this CD account.");

}

public final void deposit(double num) {

System.out.println("A CD Account can't make any additional deposit. You may open another CD account.");

}

public String toString() {

String res = String.format("%2s%25.2f%20.2f%16.2f%5s%20s", super.getId(), super.getBalance(),

this.getMatureBalance(), this.getAnnualInterestRate(), "",

this.getDateCreated());

System.out.format(res);

System.out.println();

return res;

}

public void displayMonthlyinterests() {

System.out.println();

for(int i=0;i

String res = String.format("%2s%25.2f", "Month "+Integer.toString((i+1)), (this.getBalance() + this.getMonthlyInterest()*(i+1)));

System.out.println(res);

}

}

}

Sample output  Use the Account and CDAccount classes you created from Assignment 6
. Sample output Please enter an account number to check the balance Co to exit): 200 Account Number 200 doesn't exist! Please enter an account number to check the balance Co to exit): 101.0 Account id: 1010 Account balance: $579.0 Please enter an account number to check the balance Co to exit): 1020 Account Number: 1020, Account Type: CDAccount, Account Mature Balance: $564.15 Please enter an account number to check the balance Co to exit): 1099 Account id: 1099 Account balance: $899.0 Please enter an account number to check the balance (0 to exit): 1806 Account Number: 1006, Account Type: CDAccount, Account Mature Balance: $692.24 Please enter an account number to check the balance Co to exit): 1064 Account id: 1064 Account balance: $438.0 Please enter an account number to check the balance Co to exit): 1076 Account id: 1076 Account balance: $578.0 Please enter an account number to check the balance Co to exit): 1045 Account id: 1845 Account balance: $171.0 Please enter an account number to check the balance Co to exit): 1089 Account Number: 1089, Account Type: CDAccount, Account Mature Balance: $ 15.08 Please enter an account number to check the balance C@ to exit): 0

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!