Question: In this lab, you will write a banking application that tracks deposits and withdrawals and accrues interest using the following methodology: Design a class named
In this lab, you will write a banking application that tracks deposits and withdrawals and accrues interest using the following methodology:
Design a class named Account that contains:
An int data field named id for the account (default 0) A double data field named balance for the account (default 0) A double data field named annualInterestRate that stores the current interest rate (default 0) A Date data field named dateCreated that stores the date when the account was created A no-arg constructor that creates a default account 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 from 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 $10,000, use the deposit method to deposit $3,000, and print the balance, the monthly interest, and the date when the account was created. Procedure
1. Create a class called Account.
2. Create the following methods:
public int id; public double balance; public double annualInterestRate; public java.util.Date dateCreated; public Account() public Account(int id, double balance, double annualInterestRate) public int getId() public double getBalance() public double getAnnualInterestRate() public void setId(int id) public void setBalance(double balance) public void setAnnualInterestRate(double annualInterestRate) public double getMonthlyInterest() public java.util.Date getDateCreated() public void withdraw(double amount) public void deposit(double amount)
3. Create a test program to implement the Account class and its properties. See Figure 1.
public static void main (String[] args) { Account account = new Account(1122, 20000, 4.5); account.withdraw(10000); 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()); } Figure 1
Sample output: Balance is 13000.0 Monthly interest is 48.75 This account was created at Wed Apri 30 09:03:36 EST 2015 Figure 2
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
