Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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. SAMPLE
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.
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
public class Driver{ public static void main( String[] args ){ Account account = new Account( 1122, 2000 ); account.setAnnualInterestRate( 4.5 ); account.withdraw( 2500 ); account.deposit( 3000 ); System.out.println( "Account balance: " + account.getBalance( ) ); System.out.println( "Account monthly interest rate: " + account.getMonthlyInterestRate( ) ); System.out.println( "Account date created: " + account.getDateCreated( ) ); } }
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) { if(this.balance > amount){ this.balance -= amount; } } public void deposit(double amount) { this.balance += amount; } }
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