Write a Java program that can compute the interest on the next monthly mortgage payment. The program reads the balance and the annual percentage interest rate from the console.
The interest rate should be entered as a percentage value and not as a floating-point number (e.g.: for an interest rate of 4.25%, the user should enter 4.25, and not 0.0425). The program should check to be sure that the inputs of balance and the interest rate are not negative. The program should then compute and display the interest amount as a floating-point number with 2 digits after the floating point.
Formula: the interest on the next monthly mortgage payment can be computed using the following formula: Interest = balance x (annualInterestRate / 1200)

Respuesta :

Answer:

import java.util.Scanner;

public class Main

{

public static void main(String[] args) {

    Scanner input = new Scanner(System.in);

   

    double balance, rate, interest;

   

 System.out.print("Enter the balance: ");

 balance = input.nextDouble();

 

 System.out.print("Enter the annual percentage interest rate [%4.25 must be entered as 4.25]: ");

 rate = input.nextDouble();

 

 if(balance < 0 || rate < 0)

     System.out.println("The balance and/or interest rate cannot be negative!");

 else{

     interest = balance * (rate / 1200);

     System.out.printf("The interest amount $%.2f", interest);

 }

}

}

Explanation:

Ask the user to enter the balance

Ask the user to enter the interest rate as given format

Check the balance and rate. If any negative value is entered, print an error message. Otherwise, calculate the interest using the given formula and print the interest in required format