CSCI.UA0101: Homework 8

Section 001: 50 points
Section 002: 40 points


Answer the questions stated in the following exercises by submitting plain-text or Java source code (.txt and .java extensions respectively) as stated in the exercises through NYU Classes. No word (.doc/.docx/etc.) or rich-text (.rtf) files please (in your text editor do "Save file as plain-text"). Java programs should be just the Java source code (not your .class files or Eclipse workspaces) unless otherwise stated.

In all files submitted include a documentation header using comments which include:

 * [Description of the class file]
 * @author: [Your Name]

Points will be deducted for bad coding style (up to 25% of your grade), so:

For more details regarding good coding style guidelines see the grading criteria.

Part 0 - Import an existing project into Eclipse

0 points

This assignment involves updating an existing project's codebase. In order to do so, you'll want to download and add it as a new project workspace. To use it you will need to import it into Eclipse. Follow these steps from the Eclipse menu:

  1. Eclipse Menu -> Import
  2. Expand the "General" option
  3. Select "Existing Projects into Workspace" and click "Next"
  4. Choose "Select archive file" and click "Browse"
  5. Locate and choose the "" file you downloaded
  6. Make sure that "Consumers" is checked in the list of projects to import, then click "Finish"
The project should have gotten imported and shown up on your list of projects, but you'll notice it can't compile and won't run because there are errors.

Part 1 - Implementing Interfaces and Extending Classes

40 points

This is a simple game. It is comprised of a set of different balls that are situated on the screen. The way the game works is that as balls run into each other the larger balls will consume the smaller balls. Currently only one subclass of ExpandableBall is implemented: ControllableBall. This ball is the basis for the user controlled ball which is controlled via either mouse clicks or via the arrow keys. The main() program Driver is located in the Driver class.

Your job

Your job is to complete the code for the following classes: The documentation in the classes should specify what each class is supposed to do. Your job is to come up with the implementation of these classes and to get them so they work properly. When you have completed each ball, update the corresponding TODO blocks of code in the Driver class.

Part 2 - More Features

This part is optional for regular students (Section 2).
Honors students are required to add at least two extra features of your choosing. (10 pts)

Consider adding some of these optional features:


Save and submit your entire project's JAR file (make sure you included the source code in the JAR build) on NYU Classes called Consumers.jar.

To gurantee you've done everything properly or to get experience with the command-line interface, follow the instructions below.

Building your JAR file:

Testing your JAR file:

To Test your JAR file you will need to run Java on the command-line interface (CLI), but first let's make sure you've included your source code in the .JAR file.

Verify Your Source Code

To grade your program we'll need access to the source code of your program. You should make sure that your .java files are included in the JAR. To do this, we'll switch back to your graphical interface. Open up your file browser (Finder/Windows Explorer). Go to the directory where your Consumers.jar file is stored. While you're here, go ahead and make sure that a copy of the Processing core.jar file is stored in this directory as well (you will need this later for testing). JAR files are really just specially formatted compressed .ZIP files. Go ahead and copy Consumers.jar to Now open the file by double clicking it. Open up the directory heirarchy created and make sure your .java files are located in the src/edu/nyu/cs/cs101/consumers directory located inside the ZIP. If they are present, you can close any program opened when you opened the ZIP file and delete the ZIP and/or any directory created when you opened the ZIP file and move on to the next step.

A Brief CLI Overview

You'll notice that the command-line interface is mentioned numerous times through the textbook. The CLI provides a simple way to interact with the system given a text prompt (a line where you enter a command when prompted). To a skilled user, it provides an efficient and flexible environment to allow the user to interact with the system and its numerous programs. It also makes it easy to pass different parameters to different programs. Each operating system (Windows, Mac, Linux, etc.) all have slightly different CLIs, but they all function with the same basic principles.

Starting the CLI

Running Java from the CLI

To be able to run programs we'll need to make sure that Java is accessible form the CLI. To test it, enter the command:

   java -version

If this command succeeds, it will report back the version of Java installed on your system and you can move on to the next step.

If this command failed, it will report an error message and you will need to either install the Java SE JDK if you haven't, or you will need to set your CLI PATH environment variables so that it can find the java executable. Follow the instructions for updating your PATH.

Running Your JAR File

To test that your program is runnable, you will need to change to the directory where you created the JAR file. If you saved the Consumers.jar and a copy of the Processing core.jar file to your Downloads directory the commands would look similar to one of the following:

Note: For this to work, you will need to copy the core.jar file into the same directory as your Consumers.jar file.