Advertisement
Guest User

Untitled

a guest
Feb 15th, 2019
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.51 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Interest {
  4.  
  5.  
  6. public static void main(String[] args) {
  7.  
  8. System.out.println("We will calcuate your bank balance if compounded daily, monthly, and yearly.");
  9.  
  10. //gather input
  11. Scanner s = new Scanner(System.in);
  12. System.out.println("Enter starting balance.");
  13. double startBal = s.nextInt();
  14.  
  15. System.out.println("Enter number of years your balance is compounded.");
  16. int year = s.nextInt();
  17.  
  18. System.out.println("Enter your interest rate.");
  19. //yearly compounding
  20. double rate = s.nextDouble();
  21. double yearlyRate = rate;
  22. //monthly compounding
  23. double monthlyRate = yearlyRate/12;
  24. double numMonths = year * 12;
  25. //daily compounding
  26. double dailyRate = yearlyRate/365;
  27. double numDays = year * 365;
  28.  
  29. double newBal = startBal;
  30.  
  31. for(int y = 0; y < year; y++ ) {
  32.  
  33. double interest = rate*startBal;
  34. startBal = interest + startBal;
  35.  
  36. }
  37.  
  38. double mBal = startBal;
  39.  
  40. for(int i = 0; i < numMonths; i++) {
  41.  
  42. double mInt = monthlyRate*startBal;
  43. mBal = mInt + mBal;
  44. }
  45.  
  46. double dBal = startBal;
  47.  
  48. for(int x = 0; x < numDays; x++) {
  49. double dInt = dailyRate*startBal;
  50. dBal = dInt + dBal;
  51. }
  52.  
  53. System.out.printf("Your yearly ending balance is $%1.2f\n ", startBal);
  54. System.out.printf("Your monthly ending balance is $%1.2f\n ", mBal);
  55. System.out.printf("Your daily ending balance is $%1.2f\n ", dBal);
  56.  
  57. }
  58.  
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement