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.
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...
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.
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)
3. You are invited to design a national identification number system for U.S. citizens. The ID...
3. You are invited to design a national identification number system for U.S. citizens. The ID number should: a. reflect the state, county, and city the person lives in; b. reflect the person’s date of birth; c. take into account the possibility of multiple individuals sharing identical birthday in the same city. Please EXPLAIN your design of this ID number system with appropriate examples.
Write a C++ program that will be an information system for Oregon State University using classes...
Write a C++ program that will be an information system for Oregon State University using classes as well as demonstrating a basic understanding of inheritance and polymorphism. You will create a representation of an Oregon State University information system that will contain information about the university. The university will contain a name of the university, n number of buildings, and m number of people. People can be either a student or an instructor. Every person will have a name and...
In this activity, you will select a country and analyze the banking and financial system of...
In this activity, you will select a country and analyze the banking and financial system of that country. Locate a recent article (published within the last year) that discusses your selected country's banking and financial system. You can use the Hunt Library, newspapers, new stations, or other credible sources to locate an article. Analyze the article and then provide the following in your discussion. Analyze your chosen country's banking and financial systems. Describe how money is measured in your chosen...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT