Ask Computer Engineering Expert

Objectives include:

Call and write methods with parameters and return values.
Use the String and Scanner classes.
Use if statements to validate input and control assignments.
Hand-in Requirements

All projects and laboratories will be submitted electronically through Blackboard.
Zip up your entire project directory to submit as the source.
(Right click on the project folder and follow 7-Zip > Add to "project2.zip".)
The project folder should include the following two files:

LoanPaymentCal.java
LoanPaymentCalOutput.txt
Sample Output

Here is an example of what your output should look like for a loan amount of $300000 for 2 years.
Project 2 written by Steve Robbins

Enter the loan amount and loan duration in years, for example
amount 3000 years 2
[DrJava Input Box]
Loan amount: $300000.00
Loan period: 2 years
Loan rate: 3.5%
Monthly payment: $12960.82
Month Balance Payment Remaining
1 300875.00 12960.82 287914.18
2 288753.93 12960.82 275793.12
3 276597.51 12960.82 263636.70
4 264405.64 12960.82 251444.82
5 252178.20 12960.82 239217.38
6 239915.10 12960.82 226954.28
7 227616.23 12960.82 214655.42
8 215281.50 12960.82 202320.68
9 202910.78 12960.82 189949.97
10 190503.99 12960.82 177543.17
11 178061.00 12960.82 165100.19
12 165581.73 12960.82 152620.91
13 153066.06 12960.82 140105.24
14 140513.88 12960.82 127553.06
15 127925.09 12960.82 114964.28
16 115299.59 12960.82 102338.77
17 102637.26 12960.82 89676.44
18 89938.00 12960.82 76977.18
19 77201.70 12960.82 64240.88
20 64428.25 12960.82 51467.44
21 51617.55 12960.82 38656.73
22 38769.48 12960.82 25808.67
23 25883.94 12960.82 12923.12
24 12960.82 12960.82 0.00
Total payment amount: $311059.60
Tasks

Create a directory called project2. Write a program called LoanPaymentCal and save it in project2. The program will print
Project 2 written by YOURNAME
Prompt the user for an amount and a number of years. See below for details.
Print the amount and number of years.
Call a method loanRate that takes an input loan amount as a parameter and returns an interest rate. If a jumbo loan (a loan amount is greater than or equal to $350,000), use 4.0%. For a large loan (not jumbo but greater than or equal to $100,000), use 3.5%. Otherwise, the interest rate is 3.0%. No print statements should be included in this method. The main method will print the loan rate.
Call a method loanMonthlyPayment that will take three parameters: the loan amount, rate, and number of years. It will return a monthly payment amount. This method should not print anything. The main method should print the monthly payment.
Call a method loanTotalPayment that will take 4 parameters: the loan amount, monthly payment amount, rate and the number of years. It will return the total payment amount after printing a table like the one in the sample output. The main method should then print the total payment amount.
Details

The Scanner

You will need to use Scanner to obtain input from the keyboard. You should declare a Scanner variable named console at the beginning of your main method. Only the main method will input from the keyboard.
Input Format

Inputting and verifying the input data is worth 5 points (25%). When writing you program, assume that two numbers will be entered, a double value giving the loan amount and an integer giving the loan duration in years. Use the console.nextDouble() and console.nextInt() to read in the values. This will give you 1 point out of 5 for this part of the assignment. Get the rest of the assignment working before coming back to this and improve the input handling of your program.
To get the maximum of 5 points on this part of the assignment, your program must accept input as 4 tokens and verify that the input is in an appropriate format.
The first token will be either "amount" or "years" (without the quotes). If the first token is "amount", the next is the amount of the loan and should be read in using console.nextDouble(). If the first token is "years", the next token is the number of years and should be read in with console.nextInt(). If the first token was "amount", the third token should be "years" and the number of years is read in as the fourth token using console.nextInt(). If the first token was "years", the third token should be "amount" and the amount should be read in with console.nextDouble(). Any other tokens are considered invalid input.
If invalid input is detected, the program should print an appropriate message, explaining how the input is invalid. At that point it should exit the program. You can exit the program by calling return.
You can get up to 4 points by following the above description. To obtain full credit you need to also validate the numeric input before you call console.nextInt() or console.nextDouble(). You can do this using the following Scanner methods:
boolean hasNextInt(): returns true if the next token is a valid int.
boolean hasNextDouble(): returns true if the next token is a valid double.
A typical use of these might look like this:
if (!console.hasNextInt()) {

System.exit(0);
}
int value = console.nextInt();
Outputting two decimal places

Use the method twoPlaces described in Project 1 to produce numbers with 2 decimal places. Use of this is not optional in this assignment.
Lining up columns

Do not use tabs to line up the columns. Instead, write a method called padOnLeft which takes 2 parameters, a String, s and an int, n. If the length of s is at least n, return s. Otherwise, return a string of length n obtained by putting the appropriate number of blanks at the front of s. You can create this string with a for loop.
Use this to create the columns of your table with the decimal points in each column lined up.
Calculating monthly payment

Given a loan amount, b, an monthly interest rate, r, and a loan period in months, n, you can compute monthly payment, p, using the following formula:
p = b * r
1 - (1+r)-n
Calculating loan balance

When you take out a loan, you are charged interest monthly based on an annual interest rate. If the annual rate is r, the monthly rate is r/12. The annual rate is usually represented as a fraction, a number between 0 and 1, but the interest rate will be entered as a percentage. If the annual interest rate is 15%, the annual rate will be 15/100 = .15.
If the balance at the beginning of the month is b, the balance at the end of the month before a payment is made is b + b*r/12. After the payment is made, the balance is reduced by the payment.
Test the program with the inputs shown in the sample output above and make sure your program produces the correct values. You can use tabs to line up the columsn while debugging, but in the final program you should use the padOnLeft method described above.
When you think your program is working correctly, test the program with an amount of $10000 for 2 years. Save the output to a file called LoanPaymentCalOutput.txt in the project2 directory.
Rubric

For the main method data input and output. See the details of the assignment.
If your program has a method loanRate() that takes a parameter and returns a rate correctly.
If your program has a method loanMonthlyPayment() that takes parameters and returns a monthly payment amount correctly.
If your program has a method loanTotalPayment() that takes parameters and returns a total payment amount correctly.
If the method loanTotalPayment() prints month, monthly principle, payment and remaining information per month correctly including with two decimal places and in appropriate columns.
One point for each of the following:
If the main method of your program prints "Project 2 written by [...]" and calls the three other methods.
If your submission was a Zip file named project2.zip containing two files called LoanPaymentCal.java and LoanPaymentCalOutput.txt.
If your program contains a comment that describes what the program does and contains a descriptive comment for each method.
If your program is indented properly.

Computer Engineering, Engineering

  • Category:- Computer Engineering
  • Reference No.:- M91036216
  • Price:- $115

Guranteed 48 Hours Delivery, In Price:- $115

Have any Question?


Related Questions in Computer Engineering

Does bmw have a guided missile corporate culture and

Does BMW have a guided missile corporate culture, and incubator corporate culture, a family corporate culture, or an Eiffel tower corporate culture?

Rebecca borrows 10000 at 18 compounded annually she pays

Rebecca borrows $10,000 at 18% compounded annually. She pays off the loan over a 5-year period with annual payments, starting at year 1. Each successive payment is $700 greater than the previous payment. (a) How much was ...

Jeff decides to start saving some money from this upcoming

Jeff decides to start saving some money from this upcoming month onwards. He decides to save only $500 at first, but each month he will increase the amount invested by $100. He will do it for 60 months (including the fir ...

Suppose you make 30 annual investments in a fund that pays

Suppose you make 30 annual investments in a fund that pays 6% compounded annually. If your first deposit is $7,500 and each successive deposit is 6% greater than the preceding deposit, how much will be in the fund immedi ...

Question -under what circumstances is it ethical if ever to

Question :- Under what circumstances is it ethical, if ever, to use consumer information in marketing research? Explain why you consider it ethical or unethical.

What are the differences between four types of economics

What are the differences between four types of economics evaluations and their differences with other two (budget impact analysis (BIA) and cost of illness (COI) studies)?

What type of economic system does norway have explain some

What type of economic system does Norway have? Explain some of the benefits of this system to the country and some of the drawbacks,

Among the who imf and wto which of these governmental

Among the WHO, IMF, and WTO, which of these governmental institutions do you feel has most profoundly shaped healthcare outcomes in low-income countries and why? Please support your reasons with examples and research/doc ...

A real estate developer will build two different types of

A real estate developer will build two different types of apartments in a residential area: one- bedroom apartments and two-bedroom apartments. In addition, the developer will build either a swimming pool or a tennis cou ...

Question what some of the reasons that evolutionary models

Question : What some of the reasons that evolutionary models are considered by many to be the best approach to software development. The response must be typed, single spaced, must be in times new roman font (size 12) an ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As