Question

In: Computer Science

Information: Consider a banking system with 3 classes:  BankAccount, CheckingAccount, and SavingsAccount, that you are to design...

Information:

Consider a banking system with 3 classes:  BankAccount, CheckingAccount, and SavingsAccount, that you are to design and write. Have CheckingAccount and SavingsAccount inherit from BankAccount. In BankAccount, you should include an account number, an account balance, a deposit method, a toString method, and an abstract withdraw method. Since deposits work the same way in both child classes, make sure they cannot override it. The constructor should only take an initial deposit and generate a random 5 digit account number. The toString should display the account number and the balance.

In the CheckingAccount class add a minimum balance and a standard overdraft fee of $25. Implement the withdraw method so that overdrafts are allowed, but the overdraft fee is incurred if the balance drops below the minimum balance. Override the toString method to display everything the BankAccount toString displays plus the minimum balance. Use the parent class toString to do most of the work.

In the SavingsAccount class add an annual interest rate (with a default value of 1.5%) and a method to recalculate the balance every month. Since the interest rate is annual, make sure to calculate the interest accordingly. Override the toString method to display everything the BankAccount toString displays plus the interest rate. Like the CheckingAccount toString, you should use the parent class to do most of the work.

Question:   Write the Java implementation of the BankAccount. Note, no driver is required.

Solutions

Expert Solution

Note:

As mentioned no need of Driver class.I am not including it..

Could you plz go through this code and let me know if u need any changes in this.Thank You
=================================

// BankAccount.java

public abstract class BankAccount {
   private int accountNumber;
   private double balance;

   /**
   * @param balance
   */
   public BankAccount(double balance) {
       this.accountNumber = (int) (Math.random() * ((99999 - 10000) + 1)) + 10000;
       this.balance = balance;
   }

   public void deposit(double amount) {
       if (balance > 0) {
           this.balance += amount;
       }
   }

   /**
   * @return the balance
   */
   public double getBalance() {
       return balance;
   }

   /**
   * @param balance
   * the balance to set
   */
   protected void setBalance(double balance) {
       this.balance = balance;
   }

   public abstract void withdraw(double amt);

   /*
   * (non-Javadoc)
   *
   * @see java.lang.Object#toString()
   */
   @Override
   public String toString() {
       return "AccountNumber = " + accountNumber + ", Balance = " + balance;
   }

}

========================================

==========================================

// CheckingAccount.java

public class CheckingAccount extends BankAccount {
   private final double OVERDRAFT_FEE = 25;
   private double minBalance;

   /**
   * @param balance
   * @param minBalance
   */
   public CheckingAccount(double balance, double minBalance) {
       super(balance);
       this.minBalance = minBalance;
   }

   @Override
   public void withdraw(double amt) {
       if ((getBalance() - amt) < minBalance) {
           setBalance(getBalance() - (OVERDRAFT_FEE + amt));
       } else {
           setBalance(getBalance() - (amt));
       }

   }

   /*
   * (non-Javadoc)
   *
   * @see java.lang.Object#toString()
   */
   @Override
   public String toString() {
       return super.toString() + ", Minimum Balance = " + minBalance;
   }

}

=========================================

=========================================

// SavingsAccount.java

public class SavingsAccount extends BankAccount {
   private double annualInterestRate;

   /**
   * @param balance
   * @param annualInterestRate
   */
   public SavingsAccount(double balance, double annualInterestRate) {
       super(balance);
       this.annualInterestRate = annualInterestRate;
   }

   public void calculateMonthlyInterest() {
       double monthlyInterest = getBalance() * (annualInterestRate / 12);
       deposit(monthlyInterest);
   }

   @Override
   public void withdraw(double amt) {
       if ((getBalance() - amt) >= 0) {
           setBalance(getBalance() - amt);
       }

   }
   //toString() method is used to display the contents of an object
   @Override
   public String toString() {
       return super.toString()+", Monthly Interest rate = %"+(annualInterestRate/12);
   }
}

=========================================

=========================================


Related Solutions

Information. in java Consider a banking system with 3 classes:  BankAccount, CheckingAccount, and SavingsAccount, that you are...
Information. in java Consider a banking system with 3 classes:  BankAccount, CheckingAccount, and SavingsAccount, that you are to design and write. Have CheckingAccount and SavingsAccount inherit from BankAccount. In BankAccount, you should include an account number, an account balance, a deposit method, a toString method, and an abstract withdraw method. Since deposits work the same way in both child classes, make sure they cannot override it. The constructor should only take an initial deposit and generate a random 5 digit account...
/* Work to do: 1) add toString method to BankAccount and SavingsAccount classes 2) Override the...
/* Work to do: 1) add toString method to BankAccount and SavingsAccount classes 2) Override the withdraw() in SavingsAccount so that it will not withdraw more money than is currently in the account. 3) Provide constructors for SavingsAccount 4) Add this feature to SavingsAccount: If you withdraw more than 3 times you are charged $10 fee and the fee is immediately withdrawn from your account.once a fee is deducted you get another 3 free withdrawals. 5) Implement the Comparable Interface...
Use CRC to design information system for a school. Use following classes: Professor, Class, School, Department,...
Use CRC to design information system for a school. Use following classes: Professor, Class, School, Department, and Student, Identify the main responsibilities and collaborators for each class. Then draw a UML class diagram showing the relationships (and multiplicities) between the classes.
How would you describe the "shadow banking system" and its connection with the traditional banking system?...
How would you describe the "shadow banking system" and its connection with the traditional banking system? What is securitization and why did it arise?
Design the Class Diagram (UML) for a banking system with its clients’ accounts and an ATM...
Design the Class Diagram (UML) for a banking system with its clients’ accounts and an ATM machine. Each client account holds the user’s name (String of Full Name), account number (int) and balance (int). All client account details should be hidden from other classes but the system should provide tools/methods to access, change, and display (toString for account) each of these details. The ATM machine holds the available money inside it (double) and the maximum money it can hold (double)....
Design a set of classes that keeps track of demographic information about a set of people,...
Design a set of classes that keeps track of demographic information about a set of people, such as age, nationality, occupation, income, and so on. Design each class to focus on a particular aspect of data collection. Assume the input data is coming from a text file. Create a main driver class to instantiate several of the classes.
To complete this task you are required to design an information system for Fashion clothing store...
To complete this task you are required to design an information system for Fashion clothing store to assist with their business. You have discussed Porter’s Value Chain in class and you should understand the Primary and support activities within businesses. For this task you need to concentrate on Marketing and Sales only. The development of your professional skills includes researching information systems to assist with organisational issues that are encountered in contemporary business. You will be learning important ‘agile’ skills...
explain The Structure of the Lebanese Banking System. not less than 3 paragraphs.
explain The Structure of the Lebanese Banking System. not less than 3 paragraphs.
For this assignment you will design a set of classes that work together to simulate a...
For this assignment you will design a set of classes that work together to simulate a police officer issuing a parking ticket. You should design the following classes: - The ParkedCar Class: This class should simulate a parked car. The class's responsibilities are as follows: - To know the car's make, model, color, license number, and the number of minutes that the car has been parked. - The ParkingMeter Class: This class should simulate a parking meter. The class's only...
Consider the following randomly arranged in 3 classes data of a sample. Classes frequency 5-9 9...
Consider the following randomly arranged in 3 classes data of a sample. Classes frequency 5-9 9 10-14 25 15-19 8 Plot the cumulative histogram and the polygon and interpret. (2.5+2.5+2.5=7.5) Determine the Range (5) Determine the mean and the median. (7.5+7.5=15) Determine the standard deviation. (7.5) Determine the relative frequency and determine the percentage of observation having a value equal or lower than 12. (5+2.5)
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT