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

java saving account exercise

Uploaded by

heranialemu69
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

java saving account exercise

Uploaded by

heranialemu69
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

public class SavingsAccount {

private static double annualInterestRate;


private double savingsBalance;
public SavingsAccount(double savingsBalance) {
this.savingsBalance = savingsBalance;
}

public void calculateMonthlyInterest() {


double monthlyInterest = (savingsBalance * annualInterestRate) / 12;
savingsBalance += monthlyInterest;
}
public static void modifyInterestRate(double newValue) {
annualInterestRate = newValue;
}
public double getSavingsBalance() {
return savingsBalance;
}
public static void main(String[] args) {

SavingsAccount saver1 = new SavingsAccount(2000.0);


SavingsAccount saver2 = new SavingsAccount(3000.0);

SavingsAccount.modifyInterestRate(0.04);
saver1.calculateMonthlyInterest();
saver2.calculateMonthlyInterest();
System.out.println("Current balance of Saver1:"+
saver1.getSavingsBalance());
System.out.println("Current balance of Saver2:"+
saver2.getSavingsBalance());

SavingsAccount.modifyInterestRate(0.05);
saver1.calculateMonthlyInterest();
saver2.calculateMonthlyInterest();
System.out.println("Current balance of Saver1:"+
saver1.getSavingsBalance());
System.out.println("Current balance of Saver2:"+
saver2.getSavingsBalance());
}
}

You might also like