Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- class hw {
- public static void main(String[] strings) {
- Scanner cs = new Scanner(System.in);
- System.out.print("\nLoan Amount: ");
- double loanAmount = cs.nextDouble();
- System.out.print("Number of Years: ");
- int years = cs.nextInt();
- System.out.print("Annual Interest Rate: ");
- double annualRate = cs.nextDouble();
- double monthlyRate = annualRate / 1200;
- double monthlyPayment = loanAmount * monthlyRate / (1 - 1 / Math.pow(1 + monthlyRate, years * 12));
- System.out.printf("\nMonthly Payment: %.2f\n", monthlyPayment);
- System.out.printf("Total Payment: %.2f\n\n", (monthlyPayment * 12) * years);
- double balance = loanAmount, principal, interest;
- System.out.println("Payment#\tInterest\tPrincipal\tBalance");
- for (int i = 1; i <= years * 12; i++) {
- interest = monthlyRate * balance;
- principal = monthlyPayment - interest;
- balance = balance - principal;
- System.out.printf("%-13d%-13.2f%-13.2f%.2f\n", i, interest, principal, balance);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement