Your are asked to design and implement a simple program that models the operations of a bank. Each bank account has one account owner. The bank distinguishes between two types of account owners, student and non student (person) and three types of accounts - a basic account type, a student account type for students, and a high roller account type for anyone with high balance Start with implementing the Person class and then Student. Then implement BasicAccount, StudentAccount and HighRollerAccount. Finally implement Bank. Build incrementally and test each component well in your Main class before you move on to the next.

  • Do not modify the given method signatures. Do not add other public methods to your classes.
  • Your classes must compile without errors with the given Main.java code.
  • Take advantage of inheritance and polymorphism to avoid needless duplication.
  • Do not include main() methods with your other classes.

Bank.java

public class Bank {
private BasicAccount[] accounts;
private String name;
private double maintFee;
private double intRate;
private int nextId;
private final double HIGH_ROLLER_LIMIT = 100000;

/**
* Construct a bank with initial capacity for only 2 accounts
*
* @param name The bank name
*/
public Bank(String name) {
this.name = name;
accounts = new BasicAccount[2];
}

/**
* Set the interest rate for the bank and all the accounts in it
*
* @param intRate The interest rate
*/
public void setIntRate(double intRate) {
// your code here
}

/**
* Set the maintenance fee amount for the bank and all the accounts in it
*
* @param maintFee The maintenance fee
*/
public void setMaintFee(double maintFee) {
// your code here
}

/**
* Opens a new account for the given owner with the given balance. The account IDs
* are assigned successively; e.g. First account gets ID 0, second ID 1, third ID 3, ...
* If the balance meets the high roller limit, a high roller account is opened.
* If not, a student account is opened for students and a basic account for non students.
*
* The accounts array doubles its capacity every time it is full and a new account must be
* opened. e.g. starts with length 2 (in the constructor) then becomes 4 when the third
* account must be added, then becomes 8 when the fifth must be added, then 16, and so on.
*
* @param owner The account owner
* @param balance The initial balance
* @return The account ID of the newly opened account.
*/
public int openAccount(Person owner, double balance) {
// double the accounts array if capacity has been reached

// your code here


// open the right type of account

// your code here
}

/**
* Assess the maintenance fee on all the accounts in the bank.
*
* @return The total fee collected
*/
public double assessMaintenanceFee() {
// your code here
}

/**
* Pay interest to all the accounts in the bank.
*
* Extra credit: If the new balance on any basic or student accounts meets the high roller limit, those accounts
* are converted to high roller accounts. MUST use the helper private method below to do this.
*/
public void payInterest() {
// your code here
}

/**
* Deposit the given amount to the account with the given ID (if it exists).
*
* Extra credit: If the new balance on any basic or student accounts meets the high roller limit, those accounts
* are converted to high roller accounts. MUST use the helper private method below to do this.
*
* @param acctId The account ID
* @param amount The deposit amount
*/
public void deposit(int acctId, double amount) {
// your code here
}

/**
* Withdraw the given amount from the account with the given ID (if it exists).
*
* Extra credit: If the new balance on any high roller accounts falls below the limit, those accounts are
* converted to basic or student accounts (depending on the owner). MUST use the helper private
* method below to do this.
*
* @param acctId The account ID
* @param amount The amount to withdraw
*/
public void withdraw(int acctId, double amount) {
// your code here
}

/**
* Print all accounts
*
* Implementation MUST depend on the toString() representation of accounts and print nothing else.
*/
public void printAllAccounts() {
// your code here
}

/**
* Print all the accounts of the given account owner
*
* Implementation MUST depend on the toString() representation of accounts and print nothing else.
* It MUST also depend on the .equals implementation of the Person class. Specifically, you cannot
* compare IDs or names in this method.
*
* @param owner The account owner
*/
public void printAccountsForOwner(Person owner) {
// your code here
}

/**
* Check the balance of the account with the given ID and and if it is high enough to be
* a high roller account, but it is not, the account is substituted with a new HighRollerAccount.
* If it is a high roller account but it should not be since the balance is low, it is substituted
* with a new student account if the owner is a student, or a basic account otherwise.
*
* @param acctId The account ID
*/
private void changeAccountType(int acctId) {

// Extra Credit: 10 points

// your code here
}

}

BasicAccount.java


protected int acctId;
protected Person owner;
protected String bank;
protected double balance; // never negative
protected double intRate; // the interest rate, e.g. 0.02 (for 2 %)
protected double maintFee;

public BasicAccount(int acctId, Person owner, String bank) {
// your code here
}

/**
* Deposit the given amount if positive. Negative amounts are ignored.
*
* @param amount The amount to deposit
* @return The balance after deposit was accepted
*/
public double deposit(double amount) {
// your code here
}

/**
* Withdraw the given amount if positive and if there are enough funds.
* Negative amounts are ignored. If the amount to be withdrawn is higher than the balance,
* withdraw the entire balance.
*
* @param amount The amount to withdraw
* @return The amount withdrawn
*/
public double withdraw(double amount) {
// your code here
}

public double getBalance() {
// your code here
}

public int getAcctId() {
// your code here
}

public Person getOwner() {
// your code here
}

public void setInterestRate(double intRate) {
// your code here
}

public void setMaintFee(double maintFee) {
// your code here
}

/**
* Add the accrued interest to the account.
* E.g. If balance is 100 and intRate is 0.02, balance should become 102.
*/
public void addInterest() {
// your code here
}

/**
* Withdraw the account maintenance fee
*
* @return The fee collected
*/
public double assessMaintenanceFee() {
// your code here
}

// override the toString method to return: "Account of " + owner + " with ID " + acctId + " and a balance of " + balance
// your code here


// override the equals method to return true if the acctId and bank name are equal
public boolean equals(Object other) {
// your code here
}

HighRollerAccount.java


// A high roller account has all the behaviors and properties of a basic account,
// but a zero maintenance fee is collected from a high roller account
// and when interest is added, it is added twice:
// e.g balance 100, intRate = 0.1 => 110 (from first interest added) => 121 (from second interest added)

public HighRollerAccount(int id, Person owner, String bank, double balance) {
// your code here
}

// your code here

// override the toString method to return: "High Roller " + whatever the basic account returns
// your code here

Main.java

public class Main {
/**
* Test all your classes well. The code below is given
* just to give an idea of how the client expects to use your classes.
*
* @param args
*/
public static void main(String[] args) {
Bank b = new Bank("Bank of Rupt");

b.setIntRate(0.1);
b.setMaintFee(50);

Person bob = new Person(11315, "Bob");
int bobAcctId = b.openAccount(bob, 1000);

Person alice = new Student(12512, "Alice", "SMC", 1234);
int aliceAcctId = b.openAccount(alice, 500);

Person rich = new Person(51542, "Rich P. Person");
int richAcctId = b.openAccount(rich, 1000000);

Person richStudent = new Student(23814, "Rich S. Student", "USC", 1191);
int richStudentAcctId = b.openAccount(richStudent, 100100);

// another account for Rich S. Student
b.openAccount(richStudent, 30000);

// another account for Alice
b.openAccount(alice, 100);

// another account for Bob
b.openAccount(bob, 5000);


System.out.println("All the accounts: ");
b.printAllAccounts();
System.out.println();

System.out.println("All the accounts of Alice: ");
b.printAccountsForOwner(alice);
System.out.println();

System.out.println("Paying interest : ");
b.payInterest();
b.printAllAccounts();
System.out.println();

System.out.println("Assessing maintenance fees: ");
b.assessMaintenanceFee();
b.printAllAccounts();
System.out.println();

System.out.println("Rich P. Person buys a Ferrari, Alice wins the lottery, Rich. S. Student pays tuition ...");
b.withdraw(richAcctId, 331000);
b.printAccountsForOwner(rich);
b.deposit(aliceAcctId, 100000);
b.printAccountsForOwner(alice);
b.withdraw(richStudentAcctId, 45000);
b.printAccountsForOwner(richStudent);
System.out.println();

}
}

/*
Output:

All the accounts:
Account of Person: Bob with ID 0 and a balance of 1000.0
Account of Student: Alice at SMC with ID 1 and a balance of 500.0
High Roller Account of Person: Rich P. Person with ID 2 and a balance of 1000000.0
High Roller Account of Student: Rich S. Student at USC with ID 3 and a balance of 100100.0
Account of Student: Rich S. Student at USC with ID 4 and a balance of 30000.0
Account of Student: Alice at SMC with ID 5 and a balance of 100.0
Account of Person: Bob with ID 6 and a balance of 5000.0

All the accounts of Alice:
Account of Student: Alice at SMC with ID 1 and a balance of 500.0
Account of Student: Alice at SMC with ID 5 and a balance of 100.0

Paying interest :
Account of Person: Bob with ID 0 and a balance of 1100.0
Account of Student: Alice at SMC with ID 1 and a balance of 550.0
High Roller Account of Person: Rich P. Person with ID 2 and a balance of 1210000.0
High Roller Account of Student: Rich S. Student at USC with ID 3 and a balance of 121121.0
Account of Student: Rich S. Student at USC with ID 4 and a balance of 33000.0
Account of Student: Alice at SMC with ID 5 and a balance of 110.0
Account of Person: Bob with ID 6 and a balance of 5500.0

Assessing maintenance fees:
Account of Person: Bob with ID 0 and a balance of 1050.0
Account of Student: Alice at SMC with ID 1 and a balance of 550.0
High Roller Account of Person: Rich P. Person with ID 2 and a balance of 1210000.0
High Roller Account of Student: Rich S. Student at USC with ID 3 and a balance of 121121.0
Account of Student: Rich S. Student at USC with ID 4 and a balance of 33000.0
Account of Student: Alice at SMC with ID 5 and a balance of 110.0
Account of Person: Bob with ID 6 and a balance of 5450.0

Rich P. Person buys a Ferrari, Alice wins the lottery, Rich. S. Student pays tuition ...
High Roller Account of Person: Rich P. Person with ID 2 and a balance of 879000.0
High Roller Account of Student: Alice at SMC with ID 1 and a balance of 100550.0
Account of Student: Alice at SMC with ID 5 and a balance of 110.0
Account of Student: Rich S. Student at USC with ID 3 and a balance of 76121.0
Account of Student: Rich S. Student at USC with ID 4 and a balance of 33000.0

*/

Person.java


protected int id;
protected String name;
protected String address;

public Person(int id, String name) {
// your code here
}

public void setAddress(String address) {
// your code here
}

public String getAddress() {
// your code here
}

public int getId() {
// your code here
}

public String getName() {
// your code here
}

// override the toString method to return: "Person: " + name
// your code here

// override the equals method to return true if the ID and name are equal
public boolean equals(Object other) {
// your code here
}

Student.java


// A Student has all the behaviors and properties of a Person

protected int sId;
protected String school;

public Student(int id, String name, String school, int sId) {
// your code here
}

public String getSchool() {
// your code here
}

public int getSId() {
// your code here
}

// override the toString method to return: "Student: " + name + " at " + school
// your code here

StudentAccount.java


// A student account has all the behaviors and properties of a basic account,
// but a zero maintenance fee is collected from a student account

public StudentAccount(int id, Student owner, String bank) {
// your code here
}

// your code here
Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.