Question: This needs to be in Java... ----------------------------------------- import java.util.Random; public class Account { private long accountNum; private Client client; private double balance; public Account(Client client,
This needs to be in Java...
-----------------------------------------
import java.util.Random;
public class Account {
private long accountNum; private Client client; private double balance; public Account(Client client, double balance) { this.client = client; this.balance = balance; this.accountNum = new Random().nextLong(); } public void deposit(double amt) { balance += amt; } public boolean withdraw(double amt) { if (amt > balance) { return false; } else { balance -= amt; return true; } } public long getAccountNum() { return accountNum; } public Client getClient() { return client; } public double getBalance() { return balance; } public String getName() { return client.getName(); } }
-----------------------------------------
import java.util.Scanner; import java.text.DecimalFormat;
public class Bank {
private String bankName; private Account[] accounts; private Scanner input; public Bank() { input = new Scanner(System.in); System.out.print("What is the name of this bank? "); bankName = input.next(); System.out.print("How many accounts will be in the bank? "); accounts = new Account[input.nextInt()]; for (int i = 0; i
-----------------------------------------
public class Client {
private String firstName; private String lastName; private long phoneNum; private String email; public Client(String firstName, String lastName, long phoneNum, String email) { this.firstName = firstName; this.lastName = lastName; this.phoneNum = phoneNum; this.email = email; } public String getName() { return firstName + " " + lastName; } public long getPhoneNum() { return phoneNum; } public String getEmail() { return email; } }
Part 2: Polymorphism and Lists Use the solution for Lab 3 as a base and Part 1 above. Modify the program as follows Make the Account class abstract Add an abstract void method called monthlyProcess, with no parameters Add a ChequingAccount subclass of Account. A chequing account has a monthlyFee property Note: when dealing with currencies, double is the best data type to use. Your monthlyFee property must be initialized to a random value between $5 - $10 The ChequingAccount monthlyProcess method should attempt to withdraw the monthly fee from the balance. If the balance is insufficient, an Exception should be thrown indicating the account number, balance, and fee in the Exception message. When caught, the message should be output to System.err (as opposed to System.out) Similarly, create a SavingsAccount subclass of Account The SavingsAccount has an annual interest rate property. This should be initialized to a random value between 3%-5% The SavingsAccount monthlyProcess method should add the calculated monthly interest to the balance. In the Account class, override the Object toString method. Return a String containing all the properties of an Account and its Client In each of the two subclasses, override the toString method. Begin by invoking the toString method of the parent class. To this result, append either the monthly fee information or the annual interest rate, depending on the class 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. In the Bank class, use your GenericArray class from Step 1 to store four Account instances, instead of using a classic array. Make two accounts of type ChequingAccount and two of type SavingsAccount 11. In the main method, add an option in the menu to run the monthlyProcess. 12. Add a void monthlyProcess menu to the Bank class. Loop through all Account objects in your GenericArray to invoke the monthlyProcess of each account. 13. Update the printAccounts method to use the toString method of each Account, rather than outputting all the details individually
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
