Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Good day , Please assist by running the following source code on Netbeans IDE 2 1 or any Java programming language and provide me with
Good day
Please assist by running the following source code on Netbeans IDE or any Java programming language and provide me with the screen shorts of the output. The output must show the name of the programming language being used.
import java.util.Scanner;
public class MortgageCalculator
public static void mainString args
Create a Scanner object for user input
Scanner scanner new ScannerSystemin;
Prompt user to enter loan amount
System.out.printEnter the loan amount in rands: ;
double loanAmount scanner.nextDouble;
Prompt user to enter annual interest rate
System.out.printEnter the annual interest rate as a percentage: ;
double annualInterestRate scanner.nextDouble;
Prompt user to enter loan term in years
System.out.printEnter the loan term in years: ;
int loanTermYears scanner.nextInt;
Calculate monthly interest rate
Convert annual interest rate from percentage to decimal and divide by for monthly rate
double monthlyInterestRate annualInterestRate ;
Calculate number of monthly payments
Multiply loan term in years by to get total number of payments
int numberOfPayments loanTermYears ;
Calculate monthly mortgage payment using formula:
M Prrnrn
where M is the monthly payment, P is the principal loan amount,
r is the monthly interest rate, and n is the number of payments
double monthlyPayment loanAmount monthlyInterestRate Math.pow monthlyInterestRate, numberOfPayments
Mathpow monthlyInterestRate, numberOfPayments;
Display the calculated monthly payment
Use printf to format the output to two decimal places
System.out.printfMonthly Mortgage Payment: R fn monthlyPayment;
Close the scanner to prevent resource leak
scanner.close;
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started