Advertisement
LEGEND2004

B

Dec 3rd, 2022
674
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.22 KB | None | 0 0
  1. using System;
  2.  
  3. class SavingAccount{
  4.     public static double annualInterestRate;
  5.     private double savingsBalance;
  6.     public double SavingsBalance{
  7.         get {return savingsBalance;}
  8.         set {savingsBalance = value;}
  9.     }
  10.     public void calculateMonthlyInterest(){
  11.         double x = (savingsBalance * annualInterestRate * 1.0) / 12;
  12.         savingsBalance += x;
  13.     }
  14.     public void modifyInterestRate(int newValue){
  15.         annualInterestRate = newValue;
  16.     }
  17. }
  18.  
  19. class Program{
  20.     public static void Main(){
  21.         SavingAccount saver1 = new SavingAccount();
  22.         SavingAccount saver2 = new SavingAccount();
  23.         saver1.SavingsBalance = 2000.00;
  24.         saver2.SavingsBalance = 3000.00;
  25.        
  26.         saver1.modifyInterestRate(3);
  27.         saver1.calculateMonthlyInterest();
  28.         saver2.calculateMonthlyInterest();
  29.         Console.Write($"Saver1 - {saver1.SavingsBalance}, ");
  30.         Console.Write($"Saver2 - {saver2.SavingsBalance}\n");
  31.        
  32.         saver1.modifyInterestRate(4);
  33.         saver1.calculateMonthlyInterest();
  34.         saver2.calculateMonthlyInterest();
  35.         Console.WriteLine($"Next month: Saver1 - {saver1.SavingsBalance}, Saver2 - {saver2.SavingsBalance}");
  36.     }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement