Guest User

Untitled

a guest
Dec 9th, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.09 KB | None | 0 0
  1. public class Balance {
  2.  
  3. // A person will borrow a certain amount of money, and the program will give a ton of information back to the person about what payments they need to make/ how many years it will take and so on..
  4.  
  5. public static void main(String[] args) {
  6. // Declare variables
  7. double b; // Gets the balance
  8. double a; // The amount borrowed
  9. double n; // The number of payments per year
  10. double p; // Amount paid per payment
  11. double r1; // Annual percentage rate
  12. double r; // Divided the percentage rate by 100
  13. double t; // Time in years
  14. double paidoff; // The paid off percentage
  15. double totalpayments; // The total payments
  16.  
  17. // Get some information from the user
  18. TextIO.put("Enter the amount you want to borrow: ");
  19. a = TextIO.getDouble();
  20. TextIO.put("How many payments do you want to make per year ");
  21. n = TextIO.getDouble();
  22. TextIO.put("How much money will you repay per payment ");
  23. p = TextIO.getDouble();
  24. TextIO.put("What is the annual interest rate in percentage ");
  25. r1 = TextIO.getDouble();
  26. TextIO.put("How long do you want to borrow the money for in years ");
  27. t = TextIO.getDouble();
  28.  
  29. r = r1 / 100;
  30.  
  31.  
  32. // Calculation Time
  33.  
  34. b = a*(Math.pow(1 + r/n, n * t)) - p * ((Math.pow(1 + r/n, n * t) - 1) / r/n );
  35.  
  36. // Calculates the percentage of the loan that's been paid off...
  37.  
  38. paidoff = (100 * (a - b) / a);
  39.  
  40. // Calculates the total payment after the user inputed years
  41.  
  42. totalpayments = p * n * t;
  43.  
  44.  
  45.  
  46. // Print
  47.  
  48. TextIO.put("A person who borrows $");
  49. TextIO.put(a);
  50. TextIO.put(" making ");
  51. TextIO.put(n);
  52. TextIO.put(" payments a year of $");
  53. TextIO.put(p);
  54. TextIO.putln(" each with an annual");
  55. TextIO.put("interest rate of " + r1 + "% after " + t + " years would have to repay approximately $" + b + " of that" + "\n original loan.");
  56. TextIO.putln("They have paid off " + paidoff + "% of the original loan after " + t + " years.");
  57. TextIO.putln("In that " + t + " years, $" + totalpayments + " was paid in total.");
  58.  
  59.  
  60. } // End of Main()
  61.  
  62. } // End of Class (Balance)
Add Comment
Please, Sign In to add comment