168k views
0 votes
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 (e.g.: for an interest rate of 4.25%, the user should enter "4.25") from the console. The program should check to be sure that the inputs of balance and the interest rate are not negative. After the computation, the program displays 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)

User Jbowes
by
4.7k points

1 Answer

3 votes

Answer:

// program in java.

import java.util.*;

class Main

{// main method of class

public static void main (String[] args) throws java.lang.Exception

{

try{

// object to read input

Scanner scr=new Scanner(System.in);

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

// read balance

float bal=scr.nextFloat();

System.out.print("Enter interest(in %):");

// read interest

float inte=scr.nextFloat();

// calculate monthly mortgage

float month_mort=bal*inte/1200;

// print the mortgage

System.out.printf("monthly mortgage is: %.2f",month_mort);

}catch(Exception ex){

return;}

}

}

Step-by-step explanation:

Read the balance and annual interest from user with help of Scanner object. Then calculate the monthly mortgage by formula Interest = balance x (annualInterestRate / 1200). Print the monthly mortgage.

Output:

Enter balance:10000

Enter interest(in %):4.25

monthly mortgage is: 35.42

User Jilles Van Gurp
by
5.8k points