Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Balance {
- // 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..
- public static void main(String[] args) {
- // Declare variables
- double b; // Gets the balance
- double a; // The amount borrowed
- double n; // The number of payments per year
- double p; // Amount paid per payment
- double r1; // Annual percentage rate
- double r; // Divided the percentage rate by 100
- double t; // Time in years
- double paidoff; // The paid off percentage
- double totalpayments; // The total payments
- // Get some information from the user
- TextIO.put("Enter the amount you want to borrow: ");
- a = TextIO.getDouble();
- TextIO.put("How many payments do you want to make per year ");
- n = TextIO.getDouble();
- TextIO.put("How much money will you repay per payment ");
- p = TextIO.getDouble();
- TextIO.put("What is the annual interest rate in percentage ");
- r1 = TextIO.getDouble();
- TextIO.put("How long do you want to borrow the money for in years ");
- t = TextIO.getDouble();
- r = r1 / 100;
- // Calculation Time
- b = a*(Math.pow(1 + r/n, n * t)) - p * ((Math.pow(1 + r/n, n * t) - 1) / r/n );
- // Calculates the percentage of the loan that's been paid off...
- paidoff = (100 * (a - b) / a);
- // Calculates the total payment after the user inputed years
- totalpayments = p * n * t;
- // Print
- TextIO.put("A person who borrows $");
- TextIO.put(a);
- TextIO.put(" making ");
- TextIO.put(n);
- TextIO.put(" payments a year of $");
- TextIO.put(p);
- TextIO.putln(" each with an annual");
- TextIO.put("interest rate of " + r1 + "% after " + t + " years would have to repay approximately $" + b + " of that" + "\n original loan.");
- TextIO.putln("They have paid off " + paidoff + "% of the original loan after " + t + " years.");
- TextIO.putln("In that " + t + " years, $" + totalpayments + " was paid in total.");
- } // End of Main()
- } // End of Class (Balance)
Add Comment
Please, Sign In to add comment