Advertisement
mcnealk

New Project2

Oct 9th, 2014
173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.21 KB | None | 0 0
  1. import java.util.*;
  2. /**
  3. * Write a description of class Project2 here.
  4. * Kailey McNeal
  5. * 10-9-14
  6. * Project #2
  7. */
  8. public class Project2
  9. {
  10. public static void main (String[] args)
  11. {
  12. Scanner console=new Scanner (System.in);
  13. System.out.print("Interest Rate: ");
  14. double percent=console.nextDouble();
  15. System.out.print("Initial Deposit: ");
  16. double initial=console.nextDouble();
  17. System.out.print("Time(Years) : ");
  18. int years=console.nextInt();
  19. System.out.print("Yearly Deposit: ");
  20. double extra=console.nextDouble();
  21. System.out.println();
  22. header();
  23. for (int i=1; i<=years; i++) //year
  24. {
  25. double rate=(percent/100);
  26. double interest = (initial*rate);
  27. interest=Math.round(interest*100);
  28. interest=interest/100;
  29. double balance=interest + initial;
  30. balance=Math.round(balance*100);
  31. balance=balance/100;
  32. double newbalance=balance+extra;
  33. String ival=String.valueOf(i);
  34. String initialval=String.valueOf(initial);
  35. String interestval=String.valueOf(interest);
  36. String balanceval=String.valueOf(balance);
  37. String extraval=String.valueOf(extra);
  38. String newbalanceval=String.valueOf(newbalance);
  39. System.out.print("|" + i);
  40. spaces(ival.length());
  41. System.out.print("|$" + initial);
  42. spaces(initialval.length());
  43. System.out.print("|$" + interest);
  44. spaces(interestval.length());
  45. System.out.print("|$" + balance);
  46. spaces(balanceval.length());
  47. System.out.print("|$" + extra);
  48. spaces(extraval.length());
  49. System.out.print("|$" + newbalance);
  50. spaces(newbalanceval.length());
  51. System.out.println("|");
  52. initial=newbalance;
  53. }
  54. }
  55. public static void header()
  56. {
  57. System.out.println("| Years | Initial | Interest | Balance | Deposit |New Balance|");
  58. }
  59. public static void spaces(int length)
  60. {
  61. for (int i=1; i<11-length; i++)
  62. {
  63. System.out.print(" ");
  64. }
  65.  
  66. }
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement