CS 161 – Spring 2007
Data and Expressions
Lab 2 – Coins
Due Thursday, February 8th at the BEGINNING of lab period
Overview
For this lab, you will write a Java program that will calculate the minimum number of coins (quarters, dimes, nickels, and pennies) required to make change. This will give you practice with data types and expressions. Input will come from the console, and output will be displayed in a message box.
Use good programming style: choose good variable identifiers, write comments you understand, and use white space to make your program readable.
You will read in a positive integer value from the user via the console. This value will represent the quantity (in cents) that should be converted into coins. You should include a short prompt telling the user what to do, and you should read in the value using the Scanner class. You may assume that the values are non-negative; that is, you don't have to test for negative values.
When your application is running, your console (inside Eclipse) might look like this:

The output should be displayed as a dialog box, using JOptionPane. For the input above, your output might look like this:

Note that you need not worry about improper plurals on the coin names; "1 pennies" is fine. You should have multiple lines of output, as shown above.
Note that you need to create a new project for this lab. The basic steps are the same as in the first lab. In Eclipse, go to File-> New -> Project and create a Java Project. You might name your project Coins. Next create a new Java class file by clicking on the “New Java Class” button (it is a green circle with a ‘C’ and a little +). Name the class (Coins or Change would be appropriate). Under ‘Which method stubs would you like to create?’, be sure to click on the box to create ‘public static void main(String[] args)’ before clicking the ‘Finish’ button.
All numeric values in this lab are integers (int). Remember that in Java, dividing two integers yields an integer result.
When you are finished, submit the directory containing your project as the coins lab.