You’ll be creating a loan payment calculator. This program will gather information from the user about her loan, and will then calculate the payment that’s due each month. Because each method depends on the previous method, it’s important to start this assignment early.
Exponent Method
In order to complete the calculation, you’ll need to write a method to compute the value a^{b} when b is a negative integer (your method does not need to work if b is not negative):
public static double pow(double a, int b)
(Note that we’re back to using static methods in this assignment.) Recall that a^{-b} is starting with 1 and then dividing by a and repeating that b times. For example, 1.5^{-3} = 1 / 1.5 / 1.5 / 1.5. So, if your answer starts as 1, you would then loop three times (since b is -3 in this example), and each time you would divide your answer by 1.5 (since that is a). When you’re done, answer will be 1.5^{-3}.
(You can assume that this method will be called with a negative number for b—your method does not need to work if it is called using 0 or a positive number.)
Monthly Payment Method
Second, you’ll write a method to calculate the monthly payment for a loan:
public static double monthlyPayment(double amountBorrowed, int loanLength, int percentage)
To calculate the monthly payment, you’ll use the following values:
P is the principal, the amount borrowed.
N is the number of payments. Since there will be monthly payments, this will be 12 times the length of the loan.
r is the monthly interest rate. To calculate this, divide the rate by 100 to convert it from a percentage, then by 12 to get the monthly interest rate. For a 6% loan, for example, the monthly rate is 0.005 (6 / 100 / 12).
The formula to calculate the monthly payment is:
You should use the method you write to compute the exponent, not anything provided by Java. (You may use Math.pow to work on this method while you are trying to get your pow method correct—the two methods should work in the same way—but you should use your pow method in the solution you submit.)
To help you check your work, $1000 borrowed for 5 years at 6% interest should have a monthly payment of $19.33 (your number may be slightly different due to rounding errors).
Main Method
The main method collects four pieces of information from the user:
The amount borrowed. This should be a double.
The interest rate. This should be an integer.
The minimum length of the loan. This should be an integer.
The maximum length of the loan, an integer. If the user enters a length that is not greater than the minimum length of the loan, they should be prompted again until they enter a valid number.
The main method should then display a nicely formatted table showing each year from the minimum to the maximum, and the monthly payment that corresponds.
Submitting the Program
Submit a printout of your program, and a printout of the output your program generates for the given input sequence. Use Word to print the output.
Your program must include the following documentation (comments) at the top:
1) Your name
2) The date
3) The assignment number
4) A brief description of what the program does
You must use good variable names, and comment appropriately.
Run the program using the following input data:
50000, 5, 5, 15
Notes
A few notes as you work on this assignment:
Although pow will only be used inside the monthlyPayment method in your finished program, you can call it from the main method to test it out. For example:
System.out.println(pow(1.5, -3));
will print out 1.5^-3 and you can see if the answer is correct (approximately .296 in that case).
If you want to write the monthlyPayment method first (and that method follows more closely to examples we've done in class), then you can call Math.pow in the same way: Math.pow(1.5, -3), for example. When you write your pow method, you'll want to replace Math.pow with just pow so it will call your method instead of Java's built-in method.
Lasly, there is an operator ^ in Java, but it's something different than exponent. That is, 1.5^-3 in Java will not return 0.269. In other programs you write (where you're not creating your own pow method), you would use Math.pow to calculate an exponent.
+++++++++++++++++++++++++++++++++++++++++++
Subject | Computer |
Due By (Pacific Time) | 11/03/2015 01:00 am |
Tutor | Rating |
---|---|
pallavi Chat Now! |
out of 1971 reviews More.. |
amosmm Chat Now! |
out of 766 reviews More.. |
PhyzKyd Chat Now! |
out of 1164 reviews More.. |
rajdeep77 Chat Now! |
out of 721 reviews More.. |
sctys Chat Now! |
out of 1600 reviews More.. |
sharadgreen Chat Now! |
out of 770 reviews More.. |
topnotcher Chat Now! |
out of 766 reviews More.. |
XXXIAO Chat Now! |
out of 680 reviews More.. |