Question: I need the code for this HW 3 Methods and Method Overloading (150 pts.): You will write the Java code for a program that uses

I need the code for this

HW 3 Methods and Method Overloading (150 pts.):

You will write the Java code for a program that uses a method to calculate the monthly payment for a loan. The formula for calculating a payment is shown further down. This application will produce a list of possible loan payments based on a series of annual interest rates starting with a user entered starting annual interest rate which is incremented in a loop until it reaches a user entered ending annual interest rate. The rate will be incremented by an increment rate which the user also enters.

In summary, the user will need to enter:

- A starting annual interest rate such as 4.000%, which is the decimal value 0.0400

-An ending annual interest rate such as 6.000%, which is the decimal value 0.0600

-The rate by which the starting rate will increment as it progresses towards the ending rate such as 0.25% which is the decimal value 0.0025

-The first number of years over which the loan will be repaid such as 15

- The last number of years over which the loan will be repaid such as 30

-The number of years by which the starting term will increment as it progresses towards the ending term such as 5

- A loan amount such as 100,000 dollars

The main method will:

-Acquire input from the user

- Invoke the payment calculation method within a loop.

Hint: this program requires nested loops an outer loop controlled by controlled by the interest rate as it progresses from the stating rate to the ending and an inner loop rate the term as it progresses from the stating term to the ending term. It will calculate the payment and display them from inside the inner loop.

Since the user enters annual rates and the number of years for the loan, the program will need to convert the annual values to monthly values:

- Calculate the monthly interest rate, which well abbreviate as mir (monthly interest rate), as the annual rate divided by 12.

- Calculate the numbers of months over which the loan will be repaid, which well abbreviate as mtp (months to pay), as the number of years times* 12.

Heres how to calculate a loan payment:

Annuity Factor =(mir*(1+mir)^mtp)/(((1+mir)^mtp)-1)

Assuming a 30 year loan for $180,000 and an annual rate of 0.0375 (3.75%)the results of substituting the values in the formula are:

Annuity Factor = (0.003125*(1+0.003125)^360)/(((1+0.003125)^360)-1)

Annuity Factor = 0.004631

Payment = Amount Loaned * Annuity Factor

Payment = 180000 * 0.004631

Payment = 833.61

I used ^ to indicate raising a number to a power because Excel uses the ^ for this purpose. Java, like C, C++ and C#, has no such operator. You must use the pow method in the Math class. This makes writing the annuity factor formula more awkward. You may find it easier to break this clculation into some extra steps, rather than tripping over nested parentheses:

1. Numerator = (mir*(1+mir)^mtp) = (0.003125*(1+0.003125)^360)

2. Denominator =(((1+mir)^mtp)-1)

3. Annuity Factor = Numerator / Denominator = 0.0096088 / 2.0748184

Of course you will use variables, not hardcoded values like 0.003125 and 360, in your Java program.

Use the data given in the example below to validate that methods correctly calculate loan payments.

Use a Scanner object to obtain String input from the user for all variables. See the sample programs in the Examples/Java Basics folder.

Sample Program User Prompts and Output

Enter the starting annual interest rate as a percent (n.nnn) : 4.000

Enter the ending annual interest rate as a percent (n.nnn) : 6.000

Enter the annual interest rate increment as a percent (n.nnn): 0.25

Enter the first term in years for calculating payments : 15

Enter the last term in years for calculating payments : 30

Enter the term increment in years : 5

Enter the loan amount : 100000

See output on next pages.

Payment schedule:

Interest

Rate | 15 Years | 20 Years | 25 Years | 30 Years

4.0000 739.69 605.98 527.84 477.42

4.2500 752.28 619.23 541.74 491.94

4.5000 764.99 632.65 555.83 506.69

4.7500 777.83 646.22 570.12 521.65

5.0000 790.79 659.96 584.59 536.82

5.2500 803.88 673.84 599.25 552.20

5.5000 817.08 687.89 614.09 567.79

5.7500 830.41 702.08 629.11 583.57

6.0000 843.86 716.43 644.30 599.55

Use printf to align the numbers in even columns as shown above. This may take some tinkering.

The column headings 15 Years 20 Years 25 Years 30 Years are somewhat challenging to do. They require having a separate loop before the nested loops. If you cant manage to display the headings, your project will earn a 90, assuming everything else is correct.

Use Word, Excel or OpenOffice for the test case file.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!