In: Computer Science
Define Loan Class – Add to your project. And write program in main method to test it. Note: Assume year is number of years, rate is the annual interest rate and P is principle is loan amount, then the total payment is Total payment = P *(1+ rate/12)^ year*12; Monthly Payment = TotalPayment/(year*12); java
import java.util.Scanner; public class Loan { public static void main(String[] args) { Scanner in = new Scanner(System.in); System.out.print("Enter loan amount: "); double P = in.nextDouble(); System.out.print("Enter annual interest rate: "); double rate = in.nextDouble() / 100; System.out.print("Enter number of years: "); int years = in.nextInt(); double totalPayment = P*Math.pow(1+(rate/12), years*12); double monthlyPayment = totalPayment / (years * 12); System.out.printf("Total payment is $%.2f\n", totalPayment); System.out.printf("Monthly payment is $%.2f\n", monthlyPayment); } }