A Bonus Just For You
You're on Your Own...

Due Date: Also Monday April 24, 2000 no later than 8:00 am

*Jim's Sample Solution! *

Terms and Conditions:
- This lab is worth an extra 2.5% added to your final overall class average if the applet works correctly and the interface is reasonable.
- You must work alone on this - absolutely no group work.
- This must be submitted AFTER lab 13 is done. No credit will be given if Lab 13 does not work correctly or if this lab is submitted earlier.
- The first 10 submissions will receive the credit. This will be based on the date/time stamp placed on the file by the FTP process. Mail will be sent to the class when 10 labs have been received and the bonus is no longer available
- You may get help from us but that help will be limited.

Assignment:
Create a change making applet. The user will enter through TextFields, the price and amount paid. Your applet will compute and display the total change due and the number of bills and coins that make up the change. The largest bill we will return as change will be the $20.00. This means that you will display the counts of $20, $10, $5, $1, 25¢, 10¢, 5¢, and 1¢ bills and or coins that makeup the change. You should have two Buttons: one to compute the change and one to clear the TextFields. Check the sample applet on the web page for an example.

Background Background Real numbers will not be accurate enough due to rounding errors so you must take the input from the user as reals and convert it to integers by turning the dollar amounts into pennies. Since pennies are in truth whole numbers, your change making should then be very accurate. Here is the code from Jim's applet that computes the number of pennies in the cost (which is a double) and converts that value to an int:


double cost;
int pennyCost;
cost = parseDouble(inputCost.getText( ) );
pennyCost = (int)( cost * 100);

The code ( cost * 100) computes the number of pennies in the cost - this is a real number. The code in front of it (int) converts that real number into an integer by truncating the decimal part. Figure out how to do the arithmetic first in a test applet to be sure you can compute the correct amounts. You can use the drawString() method to display the amounts. Don't even think about the GUI/Widget interface until you can compute the change correctly.

Handin Instructions:
Create a folder named according to the tradition of the first seven labs. Put the .html and .java file into that folder. DO NOT HAND IN THE .class FILE!


FTP your folder to the usual place. Look for a folder marked Lab14Bonus.


15-120 Spring 2000                                                                   Lab 14

Back to 15-120 Assignments