Advertisement
voorash

Untitled

Oct 31st, 2014
215
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.38 KB | None | 0 0
  1.  
  2. package aly;
  3.  
  4. import java.util.Scanner;
  5.  
  6. public class interest {
  7. public static void main(String[] args) {
  8.  
  9. // Constants
  10. double rate = 0;
  11. double balance = 0;
  12. int q = 0;
  13. String m = "months";
  14. String y = "years";
  15. int nmonths = 0;
  16.  
  17. // ask question
  18.  
  19. System.out.println("Welcome to the interest calcaluter");
  20. System.out.println("Enter in a ammount of money, an intrest rate, and a ammount of Years // or months (specify weather years or months and use a space between each number given), press Q to quit >> ");
  21. Scanner in = new Scanner(System.in);
  22. balance = in.nextInt();
  23. rate = in.nextInt();
  24. int nperiods = in.nextInt();
  25. String s = in.next();
  26.  
  27. double startBalance = balance;
  28. double cumulativeInterest = 0;
  29. double tempRate = rate;
  30. // converter
  31. if (s.equalsIgnoreCase(y)) {
  32. nmonths = nperiods * 12;
  33. tempRate = rate/12;
  34. }
  35.  
  36. for (int months = 1; months <= nmonths; months++) {
  37. double interest = balance * tempRate / 100;
  38. cumulativeInterest += interest;
  39. balance = balance + interest;
  40. }
  41.  
  42. System.out.println("at a " + rate + " over " + nperiods
  43. + " " + s + "(s) the interest is " + cumulativeInterest);
  44.  
  45. System.out.println("The starting balance was " + startBalance);
  46. System.out.println("The ending balance was " + balance);
  47. System.out.println("Thank you for using the interest calculator ");
  48. }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement