Question
(Subclasses of Account) In Programming Exercise, the Account class was defined to model a bank account. An account has the properties account number, balance, annual interest rate, and date created, and methods to deposit and withdraw funds. Create two subclasses for checking and saving accounts. A checking account has an overdraft limit, but a savings account cannot be overdrawn.

Programming Exercise

(The Account class) Design a class named Account that contains:
■ A private int data field named id for the account (default 0).
■ A private double data field named balance for the account (default 0).
■ A private double data field named annualInterestRate that stores the current interest rate (default 0).
Assume all accounts have the same interest rate.
■ A private Date data field named dateCreated that stores the date when the account was created.
■ A no-arg constructor that creates a default account.
■ A constructor that creates an account with the specified id and initial balance.
■ The accessor and mutator methods for id, balance, and annualInterestRate.
■ The accessor method for dateCreated.
■ A method named getMonthlyInterestRate() that returns the monthly interest rate.
■ A method named getMonthlyInterest() that returns the monthly interest.
■ A method named withdraw that withdraws a specified amount from the account.
■ A method named deposit that deposits a specified amount to the account.

Solution:

public class Exercise09_07 {
public static void main (String[] args) {
Account account = new Account(1122, 20000);
Account.setAnnualInterestRate(4.5);
account.withdraw(2500);
account.deposit(3000);
System.out.println("Balance is " + account.getBalance());
System.out.println("Monthly interest is " +
account.getMonthlyInterest());
System.out.println("This account was created at " +
account.getDateCreated());
}
}

class Account {
private int id;
private double balance;
private static double annualInterestRate;
private java.util.Date dateCreated;

public Account() {
dateCreated = new java.util.Date();
}
public Account(int newId, double newBalance) {
id = newId;
balance = newBalance;
dateCreated = new java.util.Date();
}
public int getId() {
return this.id;
}
public double getBalance() {
return balance;
}
public static double getAnnualInterestRate() {
return annualInterestRate;
}
public void setId(int newId) {
id = newId;
}
public void setBalance(double newBalance) {
balance = newBalance;
}
public static void setAnnualInterestRate(double newAnnualInterestRate) {
annualInterestRate = newAnnualInterestRate;
}
public double getMonthlyInterest() {
return balance * (annualInterestRate / 1200);
}
public java.util.Date getDateCreated() {
return dateCreated;
}
public void withdraw(double amount) {
balance -= amount;
}
public void deposit(double amount) {
balance += amount;
}
}
Solution Preview

These solutions may offer step-by-step problem-solving explanations or good writing examples that include modern styles of formatting and construction of bibliographies out of text citations and references.
Students may use these solutions for personal skill-building and practice.
Unethical use is strictly forbidden.

public class Exercise11_03 {

    public static void main(String[] args) {
       System.out.println("SavingAccount:");
       SavingAccount sa = new SavingAccount(1122, 20000);      
       for (int i = 0; i < 9; i++) {
            System.out.println("Balance is " + sa.getBalance());
            System.out.println("Withdraw 2400");
            sa.withdraw(2400);
       }
      
       System.out.println("");
       System.out.println("CheckingAccount:");
       CheckingAccount ca = new CheckingAccount(1700, 1122, 20000);
       System.out.println("Overdraft limit is " + ca.getOverdraftLimit());      
       for (int i = 0; i < 10; i++) {
            System.out.println("Balance is " + ca.getBalance());
            System.out.println("Withdraw 2400");
            ca.withdraw(2400);
       }

    }
}
This is only a preview of the solution.
Please use the purchase button to see the entire solution.
By purchasing this solution you'll be able to access the following files:
Solution.java
Purchase Solution
$1.00 $0.5
Google Pay
Amazon
Paypal
Mastercard
Visacard
Discover
Amex
View Available Computer Science Tutors 641 tutors matched
Ionut
(ionut)
Master of Computer Science
Hi! MSc Applied Informatics & Computer Science Engineer. Practical experience in many CS & IT branches.Research work & homework
5/5 (6,804+ sessions)
1 hour avg response
$15-$50 hourly rate
Pranay
(math1983)
Doctor of Philosophy (PhD)
Ph.D. in mathematics and working as an Assistant Professor in University. I can provide help in mathematics, statistics and allied areas.
4.6/5 (6,688+ sessions)
1 hour avg response
$40-$50 hourly rate
Leo
(Leo)
Doctor of Philosophy (PhD)
Hi! I have been a professor in New York and taught in a math department and in an applied math department.
4.9/5 (6,435+ sessions)
2 hours avg response

Similar Homework Solutions