Question
import java.util.Date; public class Assignment1 { 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(Balance is +
import java.util.Date; public class Assignment1 {
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("Balance is " + account.getBalance()); System.out.println("Monthly interest is " + account.getMonthlyInterest()); System.out.println("This account was created at " + account.getDateCreated()); } }
class Account { private int id; private double balance, annualInterestRate; private Date dateCreated; public Account(int id, double balance) { this.id = id; this.balance = balance; dateCreated = new Date(); } public Account() { this(0, 0); } public int getId() { return id; }
public void setId(int id) { this.id = id; }
public double getAnnualInterestRate() { return annualInterestRate; }
public void setBalance(double balance) { this.balance = balance; }
public String getDateCreated() { return dateCreated.toString(); } public double getMonthlyInterest() { return balance * annualInterestRate / 1200.0; } public double getBalance() { return balance; } public void deposit(double a) { balance += a; } public void withdraw(double i) { if(balance >= i) { balance -= i; } } public void setAnnualInterestRate(double d) { annualInterestRate = d; } }
1) What does this program do? Could you please describe it including the input (what it asks the user to input) and output (result of the code). (5-6 sentences)
2) Also, how would you test this program to make sure it works properly? Provide the output generated with the print commands pls.
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