Problem Account Class You are a programmer for the Home JMSB
Solution
//Account.java
public class Account {
//Set constant for interest rate
public final double INTEREST_RATE=0.15;
//private variables
private double balance;
private double intRate;
private double interest;
private int transactions;
//constructor
public Account() {
balance=0;
intRate=0;
interest=0;
transactions=0;
}
//constructor that takes balance, interest rate and transactions
public Account(double balance,double intRate,int transactions) {
this.balance=balance;
this.intRate=intRate;
this.transactions=transactions;
this.interest=balance*intRate ;
}
//constructor
public Account(double balance,double intRate,
double interest,int transactions) {
this.balance=balance;
this.intRate=intRate;
this.interest=interest;
this.transactions=transactions;
}
//Method to deposit amount into account
public void deposit(double amt){
balance=balance+amt;
}
//Return interest
public double getInterest(){
return interest;
}
//Return rate
public double getRate(){
return intRate;
}
//Return transactions
public int getTransaction(){
return transactions;
}
//Return balance
public double getBalance(){
return balance;
}
//Returns string representation of Account object
public String toString() {
return \"Transaction Number :\"+transactions+
\"\ Current Balance: \"+balance
+\"\ Interest Rate :\"+intRate
+\"\ Interest Earned :\"+getInterest();
}
}
----------------------------------------------------------------
//AccountUpdateCalculator.java
public class AccountUpdateCalculator {
public static void main(String[] args) {
//Create an instance of Account with balance, rate and transaction number
Account acount=new Account(1000,
0.15, 3);
//Set amount =100
double amount=100;
///print account to console
System.out.println(acount);
//calling makeDeposit method
acount=makeDeposit(acount, amount);
//calling displayTransaction method
displayTransaction(acount, amount);
}
/*
* The method makeDeposit that takes account and amount
* as argumets and deposit amount to account and return
* then account object
* */
public static Account makeDeposit(Account act,double amount){
act.deposit(amount);
return act;
}
/*
* The method displayTransaction that takes Account obect and amount
* and prints deposit and new balance
* */
public static void displayTransaction(Account act,double amount)
{
System.out.println(\"\ \ Make Deposit\");
System.out.println(\"Deposit: \"+amount);
System.out.println(\"New Balance: \"+act.getBalance());
}
}
----------------------------------------------------------------
Sample Output:
Transaction Number :3
Current Balance: 1000.0
Interest Rate :0.15
Interest Earned :150.0
Make Deposit
Deposit: 100.0
New Balance: 1100.0


