You will write 4 classes for Program 5. Assignment:The BankAccount class models an account of a customer. A BankAccount has the following instance variables: A unique account id sequentially assigned when the Bank Account is created. A balance which represents the amount of money in the account A date created which is the date on which the account is created.The following methods are defined in the BankAccount class: Withdraw – subtract money from the balance Deposit – add money to the balance Inquiry on:o Balanceo Account ido Date createdThe SavingsAccount class models a bank account which is meant for long term savings and earns interest. It inherits all the fields and methods of the BankAccount class. The SavingsAccount class has an additional instance variable, interest rate. The interest rate is a decimal representing the rate at which the account earns interest. For example, an interest rate of .01 means that the account will earn 1% interest on its balance.The following additional methods are defined in the SavingsAccount class: Calculate interest – returns the result of calculating the interest amount based on the current balance and interest rate. It does not update the balance Inquiry on interest rate. Modifying the interest rate.The CheckingAccount class models a bank account which is used to write checks and make frequent ATM deposits and withdrawals. This type of account does not earn interest. The CheckingAccount class inherits all the fields and methods of the BankAccount class. It has an additional instance variable, monthly fee. The monthly fee is an amount of money charged by the bank for its services.The following additional methods are defined in the CheckingAccount class: Deduct monthly fee – updates the balance by deducting the monthly fee Inquiry on monthly fee. Modifying the monthly fee.Program requirementsWrite the BankAccount, CheckingAccount and SavingsAccount classes using inheritance. Include a client program with a main method, rinoel_program5, which will do the following: Prompt the user for information needed to create a savings account and a checking account Create a SavingsAccount object and a CheckingAccount object using the information Prompt the user for an amount to deposit into the savings account Deposit the amount into the savings account Prompt the user for an amount to withdraw from a checking account Withdraw the amount from the checking account Deduct the monthly fees from the checking account Calculate the interest and deposit the interest amount into the savings account. Print the savings account and checking account as shown in the sample output.Sample output:Enter the amount of money to create a savings account1000Enter the interest rate of the savings account.01Enter the amount of money to create a checking account2000Enter the monthly fee of the checking account50Amount to deposit into the savings account?1000Amount to withdraw from the checking account?100Calculating and adding interest of savings accountDeducting monthly fee from checking accountSavings accountAccount ID: 1 Created on Wed Mar 29 12:21:05 EDT 2017 Balance: 2020.0 Interest Rate: 0.01Checking accountAccount ID: 2 Created on Wed Mar 29 12:21:12 EDT 2017 Balance: 1850.0 Monthly Fee: 50.0Grading:From the information provided, write a solution that includes the following: For all classes include the following:o Use of inheritance: reuse do not recode o Instance variables o Constructors o Accessor and mutator methods o Suitable toString() methods which make use of method overriding  Write a class rinoel_program5 which creates the objects and calls the required methods as described in the program requirements section.  Printed output should look like the sample output

Question
Asked Oct 28, 2019
1 views

You will write 4 classes for Program 5. 

Assignment:
The BankAccount class models an account of a customer. A BankAccount has the following instance variables:
 A unique account id sequentially assigned when the Bank Account is created.
 A balance which represents the amount of money in the account
 A date created which is the date on which the account is created.

The following methods are defined in the BankAccount class:
 Withdraw – subtract money from the balance
 Deposit – add money to the balance
 Inquiry on:
o Balance
o Account id
o Date created

The SavingsAccount class models a bank account which is meant for long term savings and earns interest. It inherits all the fields and methods of the BankAccount class. The SavingsAccount class has an additional instance variable, interest rate. The interest rate is a decimal representing the rate at which the account earns interest. For example, an interest rate of .01 means that the account will earn 1% interest on its balance.

The following additional methods are defined in the SavingsAccount class:
 Calculate interest – returns the result of calculating the interest amount based on the current balance and interest rate. It does not update the balance
 Inquiry on interest rate.
 Modifying the interest rate.

The CheckingAccount class models a bank account which is used to write checks and make frequent ATM deposits and withdrawals. This type of account does not earn interest. The CheckingAccount class inherits all the fields and methods of the BankAccount class. It has an additional instance variable, monthly fee. The monthly fee is an amount of money charged by the bank for its services.

The following additional methods are defined in the CheckingAccount class:
 Deduct monthly fee – updates the balance by deducting the monthly fee
 Inquiry on monthly fee.
 Modifying the monthly fee.

Program requirements
Write the BankAccount, CheckingAccount and SavingsAccount classes using inheritance. Include a client program with a main method, rinoel_program5, which will do the following:
 Prompt the user for information needed to create a savings account and a checking account
 Create a SavingsAccount object and a CheckingAccount object using the information
 Prompt the user for an amount to deposit into the savings account
 Deposit the amount into the savings account
 Prompt the user for an amount to withdraw from a checking account
 Withdraw the amount from the checking account
 Deduct the monthly fees from the checking account
 Calculate the interest and deposit the interest amount into the savings account.
 Print the savings account and checking account as shown in the sample output.

Sample output:
Enter the amount of money to create a savings account
1000
Enter the interest rate of the savings account
.01
Enter the amount of money to create a checking account
2000
Enter the monthly fee of the checking account
50
Amount to deposit into the savings account?
1000
Amount to withdraw from the checking account?
100
Calculating and adding interest of savings account
Deducting monthly fee from checking account
Savings account
Account ID: 1 Created on Wed Mar 29 12:21:05 EDT 2017 Balance: 2020.0 Interest Rate: 0.01
Checking account
Account ID: 2 Created on Wed Mar 29 12:21:12 EDT 2017 Balance: 1850.0 Monthly Fee: 50.0

Grading:
From the information provided, write a solution that includes the following:
 For all classes include the following:
o Use of inheritance: reuse do not recode 
o Instance variables 
o Constructors 
o Accessor and mutator methods 
o Suitable toString() methods which make use of method overriding 
 Write a class rinoel_program5 which creates the objects and calls the required methods as described in the program requirements section. 
 Printed output should look like the sample output

check_circle

Expert Answer

Step 1

Java Program:

Filename :- BankAccount.java

// Import the required package

import java.util.Date;

// Class definition

public class BankAccount {

     // Declaring instance variables

     private long accNo;

     private double balance;

     private static int number=0;

     private Date accountCreated;

     // Parameterized constructor

     public BankAccount(double balance) {

          super();

          this.accNo = number++;

          this.balance = balance;

          accountCreated=new Date();

     }

     // Setters and getters

     public double getBalance() {

          return balance;

     }

     public long getAccNo() {

          return accNo;

     }

     public Date getAccountCreated() {

          return accountCreated;

     }

     // This method will deduct the amount from the balance

     public void withdraw(double amount) {

          if(balance>=amount)

              balance = balance - amount;

     }

     public void deposit(double amount) {

          balance = balance + amount;

     }

     // Displaying the Account holder name and balance

     @Override

     public String toString() {

return " Account ID : " + accNo + " Balance=" + balance +" Date Created :"+accountCreated;

     }

}

Step 2

Filename:- SavingsAccount.java

// Define a class that extends BankAccount

public class SavingsAccount extends BankAccount {

     // Declaring instance variables

     private double interestRate;

     // Parameterized constructor

public SavingsAccount(double balance, double interestRate) {

          super(balance);

          this.interestRate = interestRate;

     }

     // Sets the interest rate for this account.

     // @param rate the monthly interest rate in percent

     public void setInterestRate(double rate) {

          interestRate = rate;

     }

     // getters

     public double getInterestRate() {

          return interestRate;

     }

     // This method will calculate the Interest

     public double calculateInterest() {

          return (getBalance() * getInterestRate());

     }

// toString method is used to display the contents of an object inside it

     @Override

     public String toString() {

return super.toString() + " Interest Rate=" + interestRate;

     }

}

Step 3

Filename:- CheckingAccount.java

// Define a class that extends BankAccount

public class CheckingAccount extends BankAccount {   //Declaring instance variables

     private double monthlyfee;

     //Parameterized constructor

public CheckingAccount(double balance, double monthlyfee) {

          super(balance);

          this.monthlyfee = monthlyfee;

     }

     //This method will deduct the Monthly fee

     public void deductFee()

     {

          withdraw(monthlyfee);

     }

     // getters ...

Want to see the full answer?

See Solution

Check out a sample Q&A here.

Want to see this answer and more?

Solutions are written by subject experts who are available 24/7. Questions are typically answered within 1 hour.*

See Solution
*Response times may vary by subject and question.
Tagged in

Engineering

Computer Science

Java

Related Computer Science Q&A

Find answers to questions asked by student like you
Show more Q&A
add
question_answer

Q: Assume that a double variable named alpha contains the value of an angle in radians. Compose a C++ s...

A: Below program uses following c++ functionsstd::setw, std:setfill, setprecision(int n) defined under ...

question_answer

Q: Translate the following pseudocode for finding the minimum value from a set of inputs into a Java pr...

A: Java program to find the minimum valueimport java.util.Scanner; public class Program{     Public sta...

question_answer

Q: Databse SQL Queries. Need to write the SQL code for pulling the total cost of our inventory. We have...

A: A SQL query is to be written that will give the total cost of inventory. Two tables are given named ...

question_answer

Q: Beacon frames in the frequency hopping spread spectrum variant of 802.11 contain the dwell time. Do ...

A: NO,  as we know the Bluetooth frame has dwell time of 625p sec for basic data rate in the frame its ...

question_answer

Q: In MS Access, which kind of values will be accepted by the databasethrough input mask>L0L0L0;0;#A...

A: An input mask in MS-Access contain 3 fields.These fields are separated by semi-colonFirst field spec...

question_answer

Q: Consider the window size is 10, bandwidth is 1500 bps, transmission delay is 2 ms atpropagation dela...

A: Given information:

question_answer

Q: Python 3.7.4 Write a statement that associates d with a one-entry dictionary that maps the str 'answ...

A: The required statement is as given below:d = {'answer':42}

question_answer

Q: The extraterrestrials living in the planet Numerion revere a specific type of integers N. In particu...

A: Program code #1:

question_answer

Q: Consider a program that declares global integer variables x, y[10]. Thesevariables are allocated sta...

A: Explanation of the code: lw $s1, 0($gp) #load value in base address to $s1addi $s1, $s1, 25 #increme...