Question: Make the following changes to your Account.java class: 1. Update the getDateCreated method to return a copy of the reference for the dateCreated field. 2.
Make the following changes to your Account.java class:
1. Update the "getDateCreated" method to return a copy of the reference for the dateCreated field.
2. Update the "withdraw" method to perform a check against an over draft. (i.e. if the balance is 100, and the withdraw amount is 200, then no withdraw is allowed and the balance stays the same.
Upload your updated Account.java file only.
SAMPLE RUN:
BEFORE THE UPDATES, USING THE ATTACHED DRIVER:
Account balance: -29500.0
Account monthly interest rate: 0.375
Account date created: Wed Dec 31 19:00:00 EST 1969
AFTER THE UPDATES, USING THE ATTACHED DRIVER (Same as last homework):
Account balance: 20500.0
Account monthly interest rate: 0.375
Account date created: Thu Nov 02 21:54:43 EDT 2017
***MODIFY THE FOLLOWING CODE***
import java.util.Date;
public class Account {
// data fields
private int id;
private double balance;
private double annualInterestRate;
private Date dateCreated;
// constructors
public Account() {
dateCreated = new Date();
}
public Account(int id, double balance) {
this.id = id;
this.balance = balance;
this.dateCreated = new Date();
}
// accessors
public int getId() {
return this.id;
}
public double getBalance() {
return this.balance;
}
public double getAnnualInterestRate() {
return this.annualInterestRate;
}
public Date getDateCreated() {
return dateCreated;
}
public double getMonthlyInterestRate() {
return annualInterestRate/12;
}
// mutators
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 void withdraw(double amount) {
this.balance -= amount;
}
public void deposit(double amount) {
this.balance += amount;
}
}
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
