Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

public class Driver{ public static void main( String[] args ){ Account account = new Account( 1122, 20000 ); account.setAnnualInterestRate( 4.5 ); account.withdraw( 2500 ); account.deposit(

public class Driver{

public static void main( String[] args ){

Account account = new Account( 1122, 20000 );

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) {

this.balance -= amount;

}

public void deposit(double amount) {

this.balance += amount;

}

}

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.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

What is management growth? What are its factors

Answered: 1 week ago

Question

Is this investment worthwhile? Why or why not?

Answered: 1 week ago