Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a Java program at the command-line that computes the monthly payment of a

ID: 669761 • Letter: W

Question

Write a Java program at the command-line that computes the monthly payment of a mortgage, given the amount of the loan (principal), the interest rate, and the number of years required to pay back the loan.

a. Write a class called Mortgage, and add the main() method to it.

b. The first command-line argument will be the principal of the loan, which will be a double. Parse this argument into a double using the Double.parseDouble() method.

c. Similarly, the second command-line argument will be the interest rate. Parse this argument into a double.

d. The third command-line argument is the number of years for the loan. This value needs to be parsed into an int, which can be done using the Integer.parseInt() method.

e. You now have all the data you need to compute the monthly payment. Use the following formulas for computing the mortgage, and display the result using the println() method. N = years x 12 //Number of payments R = interest_rate / (12 x 100) //Monthly interest rate Monthly payment = principal x (R / (1 – (1 + R)^-N))

f. To compute the power of (1 + R) to the –N, use the following Java function, which computes a to the power b: Math.pow(a, b) The return value is a double.

g. Save, compile, and run the Mortgage program. Be sure to enter the three command-line arguments. For example, the following statement computes the monthly payment for a $200,000 mortgage at 6.5 percent for 30 years: java Mortgage 200000 6.5 30 The output should display the monthly payment of the mortgage information input on the command line.

Explanation / Answer

import java.lang.*;

class compound

{

                public static void main(String []args)

                {

                                int roa=Integer.parseInt(args[0]);

                                int noy=Integer.parseInt(args[1]);

                                int amt=Integer.parseInt(args[2]);

                                float pamt=(float)(amt*Math.pow((1+(float)roa/100),noy));

                                System.out.println("Compound Interest is.."+pamt);

                }

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote