|
Written by Chitu Okoli and Bilal Abdul Kader
|
|
Friday, 19 September 2008 11:35 |
|
Page 2 of 5
Assignment 1: Interest and coins
Due: 11:59 pm on Wednesday September 23
The purpose of this assignment is for you to begin writing simple programs in Java. There are two exercises.
1. Calculate interest (2.5%)
Console
Welcome to the Interest Calculator
Enter loan amount: 520000
Enter interest rate: .05375
Loan amount: $520,000.00
Interest rate: 5.375%
Interest: $27,950.00
Continue? (y/n): y
Enter loan amount: 4944.5
Enter interest rate: .01
Loan amount: $4,944.50
Interest rate: 1%
Interest: $49.45
Continue? (y/n): n
Press any key to continue . . .
Operation
- The application prompts the user to enter a loan amount and an interest rate.
- The application calculates the interest amount and formats the loan amount, interest rate, and interest amount. Then, it displays the formatted results to the user.
- The application prompts the user to continue.
Specifications
- Create the program in one class named InterestCalculator.
- This application should round the interest that’s calculated to two decimal places, rounding up if the third decimal place is five or greater. Because of Java rounding error, it is acceptable for your results to be off by one cent ($0.01). However, if you use BigDecimal arithmetic to fix the rounding error, you will get 0.5 point bonus. (Caution: Make sure everything else is working first before going for the bonus.)
- The value for the formatted interest rate should allow for up to 3 decimal places.
- Assume that the user will enter valid double values for the loan amount and interest rate.
- The application should continue only if the user enters “y” or “Y” to continue.
2: Calculate coins for change (2.5%)
Console
Welcome to the Change Calculator
Enter number of cents (0-99): 99
Quarters: 3
Dimes: 2
Nickels: 0
Pennies: 4
Continue? (y/n): y
Enter number of cents (0-99): 55
Quarters: 2
Dimes: 0
Nickels: 1
Pennies: 0
Continue? (y/n): n
Press any key to continue . . .
Operation
- Create the program in one class named ChangeCalculator.
- The application prompts the user to enter a number of cents from 0 to 99.
- The application displays the minimum number of quarters, dimes, nickels, and pennies that represent the coins that make up the specified number of cents.
- The application prompts the user to continue.
Specifications
- Assume that the user will enter a valid integer value for the number of cents.
- The application should continue only if the user enters “y” or “Y” to continue.
Submission
To submit the assignment, do the following:
- Package your completed assignment as one single .jar file with two classes, InterestCalculator and ChangeCalculator: In BlueJ, Project -> Create Jar File... -> Continue (Main class: none; select Include source and BlueJ project files). Name the file:
"YourFirstName YourLastName Assignment 1.jar".
- E-mail the jar file to
This e-mail address is being protected from spambots. You need JavaScript enabled to view it
no later than 11:59 pm on Wednesday September 23.
- This assignment counts as 5% of your class grade.
|
|
Last Updated on Tuesday, 08 December 2009 11:16 |