Question: 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
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 studentaccount type for students, and a high roller account type for anyone with high balance. The skeleton of the code has been provided. Please complete it.
Hints: Quite a bit of the design has already been done for you. Make sure you understand well the OOP concepts of composition, inheritance and polymorphism before you write any code. 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.
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Main
public class Main { 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(); } }
Bank
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; public Bank(String name) { this.name = name; accounts = new BasicAccount[2]; } public void setIntRate(double intRate) { // your code here } public void setMaintFee(double maintFee) { // your code here } 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 } public double assessMaintenanceFee() { // your code here } public void payInterest() { // your code here } public void deposit(int acctId, double amount) { // your code here } public void withdraw(int acctId, double amount) { // your code here } public void printAllAccounts() { // your code here } public void printAccountsForOwner(Person owner) { // your code here } private void changeAccountType(int acctId) { // Extra Credit: 10 points // your code here }
}
BasicAccount
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 } public double deposit(double amount) { // your code here } 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 } public void addInterest() { // your code here } 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
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
Person
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
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 }
StudentAccount
// 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
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

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 50000 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 10500 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
Step by Step Solution
There are 3 Steps involved in it
To implement this bank system youll need to create several classes using concepts from ObjectOriented Programming OOP like inheritance and polymorphism Heres how you might approach it Step 1 Implement ... View full answer
Get step-by-step solutions from verified subject matter experts
