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

Step: 3

blur-text-image

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

Advances In Databases And Information Systems 25th European Conference Adbis 2021 Tartu Estonia August 24 26 2021 Proceedings Lncs 12843

Authors: Ladjel Bellatreche ,Marlon Dumas ,Panagiotis Karras ,Raimundas Matulevicius

1st Edition

3030824713, 978-3030824716

More Books

Students also viewed these Databases questions

Question

3. What should a contract of employment contain?

Answered: 1 week ago

Question

1. What does the term employment relationship mean?

Answered: 1 week ago