Question
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
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). All accounts have the same interest rate (static variable).
A private Date data field named dateCreated that stores the date when the account was
created. (import java.util.Date)
A no-argument 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.
A method named getMonthlyInterest() that returns the monthly interest that is accrued on
the current balance.
A method named withdraw that withdraws a specified amount from the account.
A method named deposit that deposits a specified amount to the account.
A toString method which will print the current Account Id, the balance, the monthly
interest and the date when the account was created. (FYI. The Date class also contains a
toString() method which will provide a String of the date created)
Implement the class above.
?
Write a test program that creates an array of Account objects, using a constant
MAX_ACCOUNTS to define the size of the Account array.
Prompt the user if they would like to create an account. If so, create an Account in the
array and prompt the user for the Account Id and the initial balance.
Prompt the user for the interest rate, a withdrawal amount and a deposit amount
Add an option to display all Accounts so you can see how changing the interest rate for
one account will change the interest rate for all accounts.
This is my code so far:
AccountTest.java:
import java.util.Calendar; import java.util.Date; import java.util.Scanner; public class AccountTest {
/** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub
Scanner sc=new Scanner(System.in); Account ac=new Account(1,5000.00); System.out.println("Enter the annual intrest rate"); double intrestRate=sc.nextDouble(); ac.setAnnualIntrestRate(intrestRate); Date d=new Date(); Calendar currentDate = Calendar.getInstance(); ac.setDateCreated(currentDate.getTime()); System.out.println("Date id "+ac.getDateCreated()); System.out.println("Monthly intrest rate is :"+ac.getMonthlyInterestRate()); System.out.println("Monthly intrest is :"+ac.getMonthlyInterest()); System.out.println("Enter Amount for diposite "); double dipositeAmount=sc.nextDouble(); System.out.println("The amount after diposite is :"+ac.diposite(dipositeAmount)); System.out.println("Enter Amount to withdraw :"); double withdramount= sc.nextDouble(); System.out.println("The amount remain after with draw "+ac.withDraw(withdramount)); System.out.println("The total amount is "+ac.totalBalance());
}
}
Account.java:
import java.util.Date; public class Account {
/** * @param args */ private int id=0; private double balance=0; private double annualIntrestRate=0; private Date dateCreated;
public Account() { super(); }
public Account(int id, double balance) { super(); this.id = id; this.balance = balance; }
public int getId() { return id; }
public void setId(int id) { this.id = id; }
public double getBalance() { return balance; }
public void setBalance(double balance) { this.balance = balance; }
public double getAnnualIntrestRate() { return annualIntrestRate; }
public void setAnnualIntrestRate(double annualIntrestRate) { this.annualIntrestRate = annualIntrestRate; }
public Date getDateCreated() { return dateCreated; }
public void setDateCreated(Date dateCreated) { this.dateCreated = dateCreated; }
public double getMonthlyInterestRate() { return (this.getAnnualIntrestRate()/12); } public double getMonthlyInterest() { return (getBalance() *getMonthlyInterestRate()/100); } public double withDraw(double balance) { this.setBalance(this.getBalance()-balance); return this.getBalance(); } public double diposite(double balance) { this.setBalance(this.getBalance()+balance); return this.getBalance(); } public double totalBalance() { balance =balance + getMonthlyInterest(); return balance; } }
I need the output to look like this
Sample Output
1. Add new Account
2. Display Accounts
3. Exit
Choose: 1
Enter Account ID: 2211
Enter Account Balance: 20000
Enter Account Interest Rate: 4.5
Enter Amount to Withdrawal: 2500
Enter Amount of Deposit: 3000
Account: 2211
Balance: $20500.00
Interest Rate: 4.50
Monthly Interest: $76.88
Date Created : Sat Oct 28 11:41:10 PDT 2017
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started