Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please assist i ' m trying to run the following source code on Apache NetBeans IDE 2 1 software so i can take screenshots for

Please assist i'm trying to run the following source code on Apache NetBeans IDE 21 software so i can take screenshots for my assisgnement ,i t gives me an error please assist in correcting the error.
NB. I want all calculations to be in South African Rands.
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)/
(1- Math.pow(1+ monthlyInterestRate, -numberOfPayments));
// 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

SQL Server T-SQL Recipes

Authors: David Dye, Jason Brimhall

4th Edition

1484200616, 9781484200612

More Books

Students also viewed these Databases questions

Question

What laws have been passed in an attempt to legislate ethics?

Answered: 1 week ago

Question

Nova Company

Answered: 1 week ago