Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Please use java for the following! Design a public class named Account that cont

ID: 3688029 • Letter: P

Question

Please use java for the following!

Design a public 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 1000).

- A private double data field named annualInterestRate that stores the current interest rate (default 4.50).

- A private java.util.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 a 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 (annualInterestRate/12).

- A method named withDraw that withdraws a specified amount from the account. If there are not enough funds to withdraw an amount of money, print a statement saying that there are not enough money and leave the same balance in the account.

- A method named deposit that deposits a specified amount to the account.

(Subclasses of Account) Create two subclasses of Account: CheckingAccount and SavingAccount accounts. A checking account has an overdraft limit, but a savings account cannot be overdrawn (with some limit, e.g., $50). The SavingsAccount and CheckingAccount subclasses must override the toString method of the superclass Account.

Write a test program that creates objects of Account, SavingsAccount, and CheckingAccount, and invokes their toString() methods.

Note: The point of this problem with accounts is to work with inheritance and see that properties (data fields) for superclasses are inherited by subclasses. I hope this will give you an insight on how inheritance and polymorphism works.

Explanation / Answer

import java.util.Date;

public class AccountProblem {
public static void main(String[] args) {
//create an instance object of class Stock
Account myAccount = new Account(1122, 20000.00, 0.045);
myAccount.withdraw(2500.00);
myAccount.deposit(3000.00);
//display balance, monthly interest and date of account
System.out.println("Balance: " + myAccount.balance);
System.out.println("Monthly Interest: " + myAccount.getMonthlyInterestRate());
System.out.println("Account created on: " + myAccount.dateCreated);
}
}

class Account {
//define var1, var2
int id;
double balance;
double annualInterestRate;
Date dateCreated;
//no arg constructer
Account() {
id = 0;
balance = 0.0;
annualInterestRate = 0.0;
}
//constructor with specific id and initial balance
Account(int newId, double newBalance) {
id = newId;
balance = newBalance;
}
//accessor/mutator methods for id, balance, and annualInterestRate
public int getId() {
return id;
}
public double getBalance() {
return balance;
}
public double getAnnualInterestRate() {
return annualInterestRate;
}
public void setId() {
id = newId;
}
public void setBalance() {
balance = newBalance;
}
public void setAnnualInterestRate() {
annualInterestRate = newAnnualInterestRate;
}
//accessor method for dateCreated
public void setDateCreated() {
dateCreated = newDateCreated;
}
//define method getMonthlyInterestRate
double getMonthlyInterestRate() {
return annualInterestRate/12;
}
//define method withdraw
double withdraw(double amount) {
return balance -= amount;
}   
//define method deposit
double deposit(double amount) {
return balance += amount;
}
}