0% found this document useful (0 votes)
45 views

02 Task Performance 1

This Java class defines a savings account with fields to track the balance, interest rate, and calculated monthly interest. It includes methods to initialize the account with a starting balance and interest rate, deposit and withdraw funds, calculate and apply the monthly interest to the balance, and get the current balance and interest rate.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
45 views

02 Task Performance 1

This Java class defines a savings account with fields to track the balance, interest rate, and calculated monthly interest. It includes methods to initialize the account with a starting balance and interest rate, deposit and withdraw funds, calculate and apply the monthly interest to the balance, and get the current balance and interest rate.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

public class SavingsAccount

private double balance;

private double interestRate;

private double monthlyInterestRate;

private double finalInterest;

// This constructor gets starting balance and interest rate

public SavingsAccount(double bal, double intRate)

balance = bal;

interestRate = intRate;

//The deposit method adds the deposits to the balance

public void deposit(double total)

balance += total;

//The withdraw method subtracts the withdraw amount from balance

public void withdraw (double total)

balance -= total;

//Calculates the interest rate

public void interest ()

monthlyInterestRate = ((interestRate / 100) / 12);

finalInterest = monthlyInterestRate * balance;

balance += finalInterest;

}
public void setBalance (double sb)

balance = sb;

public double getBalance()

return balance;

public double getInterestRate()

return interestRate;

public double getFinalInterest()

return finalInterest;

public static void main (String[] args) {

You might also like