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. 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

Make the following changes to your Account.java class: 1) Update the "getDateCreated"

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( ) ); } } 

method to return a copy of the reference for the dateCreated field.

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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!