CMPU 102 - Lab 1

For this lab we will write a class that represents a pocketful of change.

Part 0: Logging in

From the login screen, choose "Options->Session->OpenWindows Desktop".  Type your username and password to log in.  After logging in, type "passwd" and return in a terminal window.  Follow the prompts to choose a new password for your account.

Part 1: Download the lab files

Start eclipse by typing "eclipse &" in a terminal window and hitting return.  Wait for the main window to open.  If necessary, click on "Workbench".

Start a web browser by typing "mozilla &" in a terminal window and hitting return.  Go to the class web page:  Go to the table in the Projects section.  Right click on the link to the file "" in today's lab (12 Sep 2005) and choose "Save Link Target As...".  Save the file in your home directory.

In Eclipse, choose "File->Import->Existing Projects into Workspace" from the menu.  Click on "Select archive file", and then the "Browse" button next to this option.  In the file chooser, select the file "" from your home directory.  Click "Finish".  You should now see a project called "lab1" in the Package Explorer.

Part 2: Implement Coins class

Implement the class called Coins, which is in the file called  This file can be found by expanding the "lab1" project, then the "src" folder, and then the "edu.vassar.cs.cs102" package.  Double click on the file to open it in an editor window.

The class should have instance variables for each coin type listed below:

    pennies, nickels, dimes, and quarters

The class should provide:

  1. a zero-parameter constructor that calls the 4-parameter constructor, setting all instance variables to 0.  Hint: the first line of the zero-parameter constructor should be
    where args... is the list of arguments you want to pass to the 4-parameter constructor.

  2. a 4-parameter constructor that initilializes each data field.

  3. findCentsValue calculates and returns the total value of the coins in cents, as an integer.

  4. findDollars calculates and returns the value in dollars, as an integer. Any fractional part of a dollar should be discarded: for example, if the coins total $1.37, then this method should return the value 1.

  5. findChange calculates and returns the value of the leftover change (after the dollars are removed) as an integer. For example, if the coins total $1.37, then this method should return the value 37.

  6. toString to report the state of the Coins object.

  7. equals to compare two Coins. This method should return true only if the two objects are equal in total value.

Part 3: Testing

After you have finished the Coins class, you should run the main method in the class called CoinsTester.  The main method for this class takes a single command line parameter, which determines the upper bound of how many coins of each type to randomly create.  For example, if you pass the value "5" to CoinsTester's main method, it will randomly create from 0 to 4 of each kind of coin in the Coins objects it creates.

To execute the CoinsTester main method from within Eclipse:

  1. First, click on "" in the Package Explorer so it is highlighted.  Choose "Run->Run..." from the menu.

  2. Under "Configurations:", Click on "Java Application", and then click "New". You should see the name of the class ("CoinsTester") in the "Name:" field at the top of the dialog.

  3. Click on the tab labeled "Arguments".

  4. In the "Program arguments" box, enter the number "10".

  5. Finally, click the "Run" button at the bottom of the dialog.

You will see the output of the program in the Console window.  Try varying the value you pass to the main method in order to find the largest value you can pass in order to have two randomly-created Coins objects compare as equal.  To change the argument:

  1. Select "Run->Run..." from the menu, click "CoinsTester" under "Configurations:"

  2. Choose the "Arguments" tab

  3. Change the value you entered for "Program arguments"

  4. Then the click the "Run" button again

Note that you can re-run the last program you ran by clicking on the green toolbar button that looks like this:

Part 4: Submitting your project

Note: just to make sure everything gets submitted properly, please ask me to help you through this part.

First, save your project as a zip file:

  1. In the package explorer, click on the "lab1" project so it is highlighted.

  2. From the menu, choose "File->Export".

  3. Choose "Archive File" and click "Next".

  4. Make sure "lab1" is the only project highlighted in the left-hand pane of the window.

  5. Click on "Browse", make sure it is positioned at your home directory, and type the filename "".

  6. Make sure the "Save in zip format" and "Create directory structure for file" items are checked.

  7. Then, click "Finish".

Sending an email with your project solution:

  1. From a terminal window, type "pine" and hit return.

  2. When prompted, type "N" so you don't have to read the welcome document.

  3. From the main menu, type "C" to compose a new email message.

  4. In the "To" field, type "hovemeye".

  5. In the "Subject" field, type "CMPU 102 Lab 1".

  6. In the "Attchmnt" field, type control-T to go to the files in your home directory.

  7. Choose "" using the arrow keys and hit return.

  8. Then, type control-X to send the email, entering "Y" when you are prompted to confirm sending the email.

Part 5: Log out

When you are done, close Eclipse, and then click on the "VCCS" menu in the lower left of the screen.  Choose "Logout..." and then click "Yes" when prompted.  Always remember to log out when you are done using the system, to ensure that no one else uses your account.