Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

The exercise for this week is to write a class that simulates managing a simple

ID: 3630357 • Letter: T

Question

The exercise for this week is to write a class that simulates managing a simple bank account. The account is created with an initial balance. It is possible to deposit and withdraw funds, to add interest, and to find out the current balance. This should be implemented in class named Account that includes:
• A default constructor that sets the initial balance to zero.
• A function getBalance that returns the current balance.
• A method deposit for depositing a specified amount.
• A method withdraw for withdrawing a specified amount.
• A method addInterest for adding interest to the account.
The addInterest method takes the interest rate as a parameter and changes the balance in the account to balance*(1+interestRate).
The UML class diagram for the Account class is shown as follows:

Account:
-balance: double
+Account()
+getBalance() : double
+deposit(amount:double):void
+withdraw(amount:double):void
+addInterest(rate:double):void

Explanation / Answer

please rate - thanks

import java.util.*;
class AccountTester{
public static void main(String[] args)
{Account a=new Account();
double balance;
a.deposit(100);
balance=a.getBalance();
System.out.println("after deposit account has $"+balance);
a.withdraw(60);
balance=a.getBalance();
System.out.println("after withdrawal account has $"+balance);
a.addInterest(.05);
balance=a.getBalance();
System.out.println("after interest account has $"+balance);

}
}


---------------------------------


class Account
{
private double balance;
public Account()
{balance = 0;
}
public void deposit(double amount)
{balance = balance + amount;
}
public void withdraw(double amount)
{balance-=amount;
}
public double getBalance()
{return balance;
}
public void addInterest(double interestRate)
{balance*=(1+interestRate);}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote