In this lab, you will write a banking application that tracks deposits and withd
ID: 3806339 • Letter: I
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 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
Explanation / Answer
Accountdrv.java
public class Accountdrv {
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());
}
}
Account.java
public
class Account {
private int id;
private double balance;
private double annualInterestRate;
private java.util.Date dateCreated;
double data[] = new double[20];
public Account() {
dateCreated = new java.util.Date();
}
public Account(int id, double balance, double annualInterestRate) {
this.id = id;
this.balance = balance;
this.annualInterestRate = annualInterestRate;
dateCreated = new java.util.Date();
}
public int getId() {
return this.id;
}
public double getBalance() {
return balance;
}
public double getAnnualInterestRate() {
return annualInterestRate;
}
public void setId(int id) {
this.id =id;
}
public void setBalance(double balance) {
this.balance = balance;
}
public void setAnnualInterestRate(double annualInterestRate) {
this.annualInterestRate = annualInterestRate;
}
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;
}
}
Output
Balance is 13000.0
Monthly interest is 48.75
This account was created at Tue Mar 28 20:47:40 IST 2017
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.