CMPU 102 - Lab 3

In this lab you will modify an existing GUI program (a game) to add a new feature and remove an arbitrary limitation.  One of the best ways to learn about programming is to read and modify existing programs.

The program that you will modify is a game in which the user places disks of various sizes into a rectangular bin.  The game continues until the user places a disk so that it either touches one of the edges of the bin, or overlaps an existing disk.


Your Tasks

Your first task is to change the program so that it displays the number of disks that have been placed in the bin in the upper right hand corner of the screen.  This number should be displayed in black text, and should be visible at all times  For example, if the user places a disk in a part of the screen where current number of disks is displayed, it should not cover up the number.

Your second task is to remove the limit on the number of disks that may be placed by the user.  As initially written, the game only allows the user to place a fixed number of disks, as specified by the constant MAX_DISKS.  You should change the program so that any number of disks may be placed.  However, you should do this

  1. without adding any new fields to the class, and
  2. without changing the type of any existing field

Getting Started

Start a web browser using the small Firefox button on the task bar at the bottom of the screen, or by typing

firefox &
in a terminal window and hitting return.  Go to the class web page, scroll down to the "Labs" section, and download the file lab3.zip into your home directory.

Start Eclipse by typing

eclipse &
in a terminal window and hitting return.  Once it starts up, choose "File->Import->Existing Projects into Workspace" from the menu, click the "Next" button, click "Select archive file", select the file "lab3.zip" in your home directory, and click the "Finish" button.  You will see a new project called "lab3" in the Package Explorer.

To run the main method of the "BinPacking" class:

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

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

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

Once you have set up Eclipse to run BinPacking's main method, you can re-run it by clicking on the green toolbar button that looks like this:

When You Are Done

When you are done, run the program and demonstrate to me that it can handle more than 20 disks in the bin at the same time.

Submitting Your Work

Submit your completed project by entering the following commands in a terminal window (pressing return after each command):

cd
cd eclipse-workspace
submit102 lab3