Answered step by step
Verified Expert Solution
Link Copied!

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 21 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 main(String[] args){
// Create a Scanner object for user input
Scanner scanner = new Scanner(System.in);
// Prompt user to enter loan amount
System.out.print("Enter the loan amount in rands: ");
double loanAmount = scanner.nextDouble();
// Prompt user to enter annual interest rate
System.out.print("Enter the annual interest rate as a percentage: ");
double annualInterestRate = scanner.nextDouble();
// Prompt user to enter loan term in years
System.out.print("Enter the loan term in years: ");
int loanTermYears = scanner.nextInt();
// Calculate monthly interest rate
// Convert annual interest rate from percentage to decimal and divide by 12 for monthly rate
double monthlyInterestRate =(annualInterestRate /100)/12;
// Calculate number of monthly payments
// Multiply loan term in years by 12 to get total number of payments
int numberOfPayments = loanTermYears *12;
// Calculate monthly mortgage payment using formula:
// M = P[r(1+r)^n]/[(1+r)^n -1]
// 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(1+ monthlyInterestRate, numberOfPayments))/
(Math.pow(1+ monthlyInterestRate, numberOfPayments)-1);
// Display the calculated monthly payment
// Use printf to format the output to two decimal places
System.out.printf("Monthly Mortgage Payment: R %.2f%n", monthlyPayment);
// Close the scanner to prevent resource leak
scanner.close();
}
}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Oracle Database 10g Insider Solutions

Authors: Arun R. Kumar, John Kanagaraj, Richard Stroupe

1st Edition

0672327910, 978-0672327919

More Books

Students also viewed these Databases questions

Question

Evaluate the importance of the employee handbook.

Answered: 1 week ago

Question

Discuss the steps in the progressive discipline approach.

Answered: 1 week ago