{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

project2

# project2 - In Java use the power function for this...

This preview shows pages 1–2. Sign up to view the full content.

CS 240 Project 2 Summer 2009 Due Date: Wednesday, July 15, 4:00 p.m. Upload to WebCT the zipped file of your complete NetBeans project (named yourLastName_project2). Complete the following program: Write program 4.21 from your textbook (page 135-136). Your output should be displayed in columns as shown in your book. Some guidelines: Use comments to divide your code into the following sections: Variable declarations Get user input (loan amount and loan period in years) Display table headings Calculate and display monthly payment and total cost of the loan (these two steps are done within a loop) Get User input: You must use a loop to validate the user input; the loan amount must be greater than 0; loan period must be greater than 0. Calculations: The formula for monthly payment (M) is: M = P * (J / ( 1 – (1 + J) ^ -N) where: P = principal (the loan amount) N = length of the loan in months (note that the user enters the length in years) J = monthly interest rate

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: In Java, use the power function for this formula (although your variable names must be more meaningful): M = P * J / (1 – (Math.pow( 1 + J , -N ))) • The total cost of the loan is simply the monthly payment * length of the loan in months Output (sample program run with output follows on next page): • Display interest rate to three decimal places • Display monetary amounts to two decimal places, and separate thousands with a comma • You may set up columns with printf or use tab (“\t” between columns NOTE: If some of your amounts differ from those shone below by 1 penny, that is ok. The difference lies in when the rounding to decimal places occurred, and may vary slightly. run: Enter loan amount: 10000 Enter number of years: 5 Interest Rate Monthly Payment Total Payment 5.000 188.71 11,322.74 5.125 189.28 11,357.13 5.250 189.85 11,391.59 5.375 190.43 11,426.11 5.500 191.01 11,460.69 7.875 202.16 12,129.97 8.000 202.76 12,165.83...
View Full Document

{[ snackBarMessage ]}

### Page1 / 2

project2 - In Java use the power function for this...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online