In: Computer Science
There is a cost of money. When someone loans you money, they expect to profit (maybe just by your goodwill). Notice that car dealers and others who are financing what you buy will usually show you the monthly payments, and avoid talking about the full cost with interest. It would be helpful to calculate the monthly payments given the amount loaned, the interest rate, and the number of payments you are expected to make. In this assignment, you will implement one standard formula for computing monthly payments.
Set up and run java, javac, and an IDE (Eclipse) on your computer Create a class main method variables strings mathematical operators assignment operator input/output Eclipse IDE Develop a Loan Calculator (as a Java standalone application) to calculate and display the monthly payment for a loan. The user will be asked to enter the loan amount, the interest rate, and the number of payments. The formula used for such a calculation is: ??????? = ?????????? ∗ ( ( ???????????? ??.? ) (? − (? + ???????????? ??. ? ) −????????????????) ) For example, for a loan amount of $225,000 with the APR 10% and 360 payments, the monthly payment is: ??????? = ?????? ∗ ( ( ?? ??.? ) (?.? − (?.? + ?? ??.? ) −???) ) Payment, loan amount, APR, 12.0, and 1.0 are real numbers; whereas N=number of payments is an integer. If you wish to use other formulas, please feel free to use them.
import java.util.Scanner;
public class LoanCalculator {
public static void main(String[] args) {
Scanner sc = new
Scanner(System.in);
// reading data from user
double amount, interestRate;
int payments;
// loop so that ask user until they
enter number greater than 0
while (true) {
System.out.println("Enter loan amount: ");
amount =
sc.nextDouble();
if (amount >
0)
break;
System.out.println("The value must be greater than 0");
}
// loop so that ask user until
they enter number greater than 0
while (true) {
System.out.println("Enter Interest rate: ");
interestRate =
sc.nextDouble();
if (interestRate
> 0)
break;
System.out.println("The value must be greater than 0");
}
// loop so that ask user until they
enter number greater than 0
while (true) {
System.out.println("Enter number of payments: ");
payments =
sc.nextInt();
if (payments
> 0)
break;
System.out.println("The value must be greater than 0");
}
// using with given
formula
double payment = amount *
((interestRate / 12.0) / 1 - Math.pow((1 + interestRate / 12.0), -1
* payments));
System.out.println("Payment is : "
+ payment);
}
}
Note : If you like my answer please rate and help me it is very Imp for me