Call and write methods with parameters and return values

Assignment Help Basic Computer Science
Reference no: EM13499096

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()) {
<print appropriate message>
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.

Reference no: EM13499096

Questions Cloud

Explain cyclohexane has a freezing point : Cyclohexane has a freezing point of 6.50 degrees C and a Kf of 20.0 degree C/m . What is the freezing point of a solution made by dissolving 0.463g of biphenyl (C12H10) in 25.0g of cyclohexane
How much work is done by brutus lifting the weights : Brutus, a champion weightlifter, raises 240 kg of weights a distance of 2.70 m. How much work is done by Brutus lifting the weights
Define the surroundings to the system : A piston performs 450 L*atm of irreversible work on the surrounding, while the cylinder in which it is placed expands from 10. L to 25L. At the same time, 45 J of hear is transferred from the surroundings to the system.
What is the work done on the refrigerator by the machine : A mover's dolly is used to transport a refrigerator up a ramp into a house. The refrigerator has a mass of 108 kg. What is the work done on the refrigerator by the machine
Call and write methods with parameters and return values : Call and write methods with parameters and return values.
Explain if the room temperature is 300 k what mass of ice : If the room temperature is 300 K what mass of ice can be produced in 1 hour by a 0.35-hp motor that is running continuously. Assume that the refrigerator is perfectly insulated and operates at the maximum theoretical efficiency.
What light intensity emerges from the last filter : Unpolarized light of intensity I_0 is incident on a stack of 7 polarizing filters, each with its axis rotated 15 (degrees) cw with respect to the previous filter. What light intensity emerges from the last filter
Explain each of the four cylinders of a combustion engine : Each of the four cylinders of a combustion engine has a displacement of 2.0L. If each pison in the four cylinders is displaced against a pressure of 2.0 atm and each cylinder is ignited once per second
What light intensity emerges from the second filter : Unpolarized light with intensity 370 W/ m^2 passes first through a polarizing filter with its axis vertical, What light intensity emerges from the second filter

Reviews

Write a Review

Basic Computer Science Questions & Answers

  Considerations and network device security

Cnonsiderations and Network Device Security

  Rank algorithms in terms of how efficiently they use memory

Rank the algorithms in terms of how efficiently they use memory.

  What is cloud computing

What is cloud computing? How far back can you find the first usage of the term? Give examples of typical applications of cloud computing.

  What is the technique called

In the transport layer, data transmission is controlled to ensure data integrity and avoid data loss. What is the technique called?

  Write a function which has this exact signature

however. As an example, if the main() function were: int main() { double x[] = {2,4,4,4,5,5,7,-9}; cout

  Use to create style sheets for your web pages

Write a 2-3 page essay that compares the features of two different CSS software packages and describe which you as a web designer might use to create style sheets for your Web pages and why. Explain the benefits of using CSS in developing your web..

  Design linked list class hold customer name and phone number

Design your own linked list (LL) class to hold customer names and phone numbers. The class should have member functions for appending, inserting, deleting, searching and displaying nodes.

  User defined company class

Create a user defined Company class the class will include Company Name, Stock Symbol and stock value per share. Include a parameterized constructor and get methods for each of the instance variables. Also include a toString method.

  Brief research on the different types of uml modeling tools

Conduct brief research on the different types of UML modeling tools that are available out there. Choose one that you think is the best to use. What did you like about this one that made it superior to other tools that you researched? Explain.

  Who are learning software programming

Discuss when scripting should be taught to individuals

  Cloud provider secure large amount of capital

Few organizations tend to prefer operating expense models. whether Cloud providers will continue to secure large amount of capital....or will equity firms stop their funding?

  Converting binary numbers in decimal

Convert the given binary numbers in decimal: 101110; 1110101; and 110110100. Convert the given decimal numbers to bases indicated.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd