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: 3657837 • 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 zero. 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 it 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 balanced* 1+rate). The UML diagram for the Account class is shown in the following UML diagram. The Account Class

Explanation / Answer

public class Account
{
private double balance;

public Account()
{
balance = 0.0;
}

public double getBalance()
{
return balance;
}

public void deposit(double amount)
{
balance += amount;
}

public double withdraw(double amount)
{
balance -= amount;
}

public void addInterest(double rate)
{
balance = balance*(1+rate);
}
}

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