Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

import java.util.Date; public class Account { private int id; private double balance; private double annualInterestRate; private Date DateCreated; / / No - arg constructor public

import java.util.Date;
public class Account {
private int id;
private double balance;
private double annualInterestRate;
private Date DateCreated;
// No-arg constructor
public Account(){
id =0;
balance =0.0;
annualInterestRate =0.0;
DateCreated = new Date();
}
// Constructor with specified id and initial balance
public Account(int id, double initialBalance){
this.id = id;
balance = initialBalance;
annualInterestRate =0.0;
DateCreated = new Date();
}
// Accessor and mutator methods for id
public int getId(){
return id;
}
public void setId(int id){
this.id = id;
}
// Accessor and mutator methods for balance
public double getBalance(){
return balance;
}
public void setBalance(double balance){
this.balance = balance;
}
// Accessor and mutator methods for annualInterestRate
public double getAnnualInterestRate(){
return annualInterestRate;
}
public void setAnnualInterestRate(double annualInterestRate){
this.annualInterestRate = annualInterestRate;
}
// Accessor method for dateCreated
public Date getDateCreated(){
return DateCreated;
}
// Method to calculate monthly interest rate
public double getMonthlyInterestRate(){
return annualInterestRate /12/100;
}
// Method to withdraw a specified amount
public void withdraw(double amount){
if (amount >0 && amount <= balance){
balance -= amount;
} else {
System.out.println("Invalid withdrawal amount.");
}
}
// Method to deposit a specified amount
public void deposit(double amount){
if (amount >0){
balance += amount;
} else {
System.out.println("Invalid deposit amount.");
}
}
public static void main(String[] args){
// Creating an Account object with specified values
Account harry = new Account();
harry.setId(1122);
harry.setBalance(20000);
harry.setAnnualInterestRate(4.5);
// Withdraw $2,500
harry.withdraw(2500);
// Deposit $3,000
harry.deposit(3000);
// Displaying account information
System.out.println("Id ="+ harry.getId());
System.out.println("Balance = $"+ harry.getBalance());
System.out.println("Monthly Interest = $"+(harry.getBalance()* harry.getMonthlyInterestRate()));
System.out.println("Date Created ="+ harry.getDateCreated());
}
} flowchart of this

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered 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