brandong512

Java Monthly Compound Interest Program

Sep 23rd, 2013
284
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.19 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. class calculator{
  4.  
  5. private double interest_principal, month_interest, interest_amount;
  6. private double principal  = 1000;
  7. private int a, c;
  8.  
  9.         double cinterest (int x){
  10.         interest_amount = Math.pow(1 + 2.65/100, x) - 1;
  11.         return(interest_amount * principal);
  12.         }
  13. }
  14.  
  15. class intcalc{
  16.  
  17.         public static void main(String[] args){
  18.  
  19.                 calculator interest = new calculator();
  20.                 Scanner uinput = new Scanner(System.in);
  21.                 int months[] = {2, 5, 10, 500};
  22.                 int user_months;
  23.  
  24.                         for(int b=0;b<4;b++){
  25.                                 System.out.println("Interest at " +
  26.                                 months[b] + " months is: " + interest.cinterest(months[b]));
  27.                                  
  28.                         }              
  29.                 System.out.print("Enter # of months for interest calculation: ");
  30.                 user_months = uinput.nextInt();
  31.                 System.out.println("Interest amount after " + user_months + " months is: "
  32.                                                 + interest.cinterest(user_months));
  33.         }    
  34.      
  35. }
Add Comment
Please, Sign In to add comment