Here is my attempt: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 specific 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 withdraw that withdraws a specified amount from the account
- A method named deposit that deposits a specified amount to the account.
Write a test program that creates an Account object with an account ID of 1122, a balance of $20,000, and an annual interest rate of 4.5%. Use the withdraw method to withdraw $2,500, use the deposit method to deposit $3,000 and print the balanace, the monthly interest, and the date when this account was created.
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; } }
My code does not compile. And I get the following error messages. I have no clue what the error messages mean and how I would fix them.
How can I get my program to compile and work?AccountProblem.java:10: cannot find symbol
symbol : constructor Account(int,double,double)
location: class Account
Account myAccount = new Account(1122, 20000.00, 0.045);
^
AccountProblem.java:48: cannot find symbol
symbol : variable newId
location: class Account
id = newId;
^
AccountProblem.java:51: cannot find symbol
symbol : variable newBalance
location: class Account
balance = newBalance;
^
AccountProblem.java:54: cannot find symbol
symbol : variable newAnnualInterestRate
location: class Account
annualInterestRate = newAnnualInterestRate;
^
AccountProblem.java:58: cannot find symbol
symbol : variable newDateCreated
location: class Account
dateCreated = newDateCreated;
^
5 errors