Advertisement
tampurus

46 Interface simple and compound interest

May 9th, 2022 (edited)
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.75 KB | None | 0 0
  1. import java.io.*;
  2. interface Interest{
  3.     double p=5000, t=2, r=18;
  4.     double SimpleInterest();
  5.     double CompoundInterest();
  6. }
  7. class Main implements Interest{
  8.     public double SimpleInterest(){
  9.         return (p * t * r)/100;
  10.     }
  11.     public double CompoundInterest(){
  12.         return p * (Math.pow(1+r/100, t) - 1);//principal * (Math.pow((1 + rate/100), (time * number))) - principa
  13.     }
  14.     public static void main (String args[]){
  15.         Main obj = new Main();
  16.         double ci = obj.CompoundInterest();
  17.         double si = obj.SimpleInterest();
  18.         System.out.println("Simple interest is "+si);
  19.         System.out.println("Compound interest is "+ci);
  20.     }
  21. }
  22. /*
  23. Simple interest is 1800.0
  24. Compound interest is 1961.9999999999993
  25. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement