import java.util.Scanner; public class MortgageCalculator2 { public static void main(String args[]) { Scanner in = new Scanner(System.in); // 1. Get principal, term, monthl interest rate System.out.print("Please enter home price: "); double price = in.nextDouble(); System.out.print("Please enter percentage of down payment: "); double principal = price * (100.0 - in.nextInt()) / 100; System.out.print("Please enter mortgage term (in years): "); int term = 12 * in.nextInt(); System.out.print("Please enter annual interests rate: "); double r = in.nextDouble() / 100 / 12; // 2. Apply the formula (handle the case where r is 0) double monthlyPayment; if (r > 0) monthlyPayment = r * principal * Math.pow((1 + r), term) / (Math.pow((1 + r), term) - 1); else monthlyPayment = principal / term; // 3. Display the result System.out.println("Your monthly payment is: " + monthlyPayment); in.close(); } }