Interest Calculator
File Name: InterestCalculator.java
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73package algorithms.math; import java.util.Scanner; public class InterestCalculator { public static void main(String args[]) { int accountId; double balance; double interestRate; Scanner sc = new Scanner(System.in); System.out.println("Enter the Account ID"); accountId = sc.nextInt(); System.out.println("Enter the Balance"); balance = sc.nextDouble(); System.out.println("Enter the Intrest Rate"); interestRate = sc.nextDouble(); Account account = new Account(accountId, balance, interestRate); int noOfYear; System.out.println("Enter the Year"); noOfYear = sc.nextInt(); double answer = calculateInterest(account, noOfYear); System.out.format("%.3f", answer); } public static double calculateInterest(Account account, int noOfYear) { double temp = noOfYear * account.getInterestRate() / 100; return (account.getBalance() * (account.getInterestRate() + temp) / 100); } } class Account { private int id; private double balance; private double interestRate; Account(int id, double balance, double interestRate) { this.id = id; this.balance = balance; this.interestRate = interestRate; } public int getId() { return this.id; } public void setId(int id) { this.id = id; } public double getBalance() { return this.balance; } public void setBalance(double balance) { this.balance = balance; } public double getInterestRate() { return this.interestRate; } public void setInterestRate(double interestRate) { this.interestRate = interestRate; } } // Compile and Run the below command. // javac algorithms/math/InterestCalculator.java && java algorithms.math.InterestCalculator