Computer Science 252
Problem Solving with Java

Spring 2016, The College of Saint Rose

Lab 10: Final Project
Proposal Due: 11:59 PM, Thursday, April 14, 2016
Design Due: 4:00 PM, Tuesday, April 26, 2016
Program Due: 4:00 PM, Thursday, May 5, 2016

This lab serves as a final programming project for the course. You are to propose, design, and implement a program that is interesting to you to demonstrate what you have learned this semester. You have a great deal of freedom in choosing what to program for this project. However, it must be an effective demonstration of your skills. More details can be found below.

This project will count for 150 points, about twice as much as a typical lab. See the "Grading" section for details.

Ground Rules

You may work individually or in a group of 2 or 3 on this program. While you may ask for help from your instructor or from the tutors in the Academic Success Center, that help will be more limited than for regular lab assignments. Additionally, any help you receive must be clearly documented in the comment at the top of your program (i.e., who helped you and exactly what that help was). If you work in a group, you will be required to include a detailed breakdown of who was responsible for which parts of your design and implementation. Group projects will earn a single grade, except in the rare situation where it becomes clear that a group member has not contributed significantly to the project. Also, the scope of the project is expected to be larger if you are working in a group.


You may find it difficult to estimate the programming effort that will be required for programs you are considering. Please discuss ideas with with me before going too far.

Your project should showcase many of the programming skills you have worked on this semester. Projects of an appropriate scope will very likely include several of the major ideas and constructs we have seen this semester (graphics primitives, mouse/keyboard event handling, custom classes, active objects, Swing GUIs, recursive structures and methods, ArrayLists/arrays) as well as most of what you knew coming in (conditionals, loops, random numbers, files, methods). Using the material covered late in the semester is encouraged, and will likely make for a more fun and interesting project, but this is not a requirement. You are also welcome and encouraged to make use of Java constructs and parts of the Java API that we have not used this semester, but check first.

There are two preliminary items to submit for this project.


By 11:59 PM, Thursday, April 14, 2016, submit a written proposal (by email or in hard copy), a few paragraphs long, describing your intended project. Clearly state what your program should do and which programming constructs you expect to use to complete your project. Please submit earlier if you can, so I am not overwhelmed with submissions at the deadline. I will make every effort to read these and give you feedback immediately. Once your proposal is accepted, your grade for the functionality portion of the project will be based on how well your submitted program matches what you proposed.

Here is a sample of an appropriate proposal.

For my final project, I plan to design and implement a simplified version of the "Fruit Ninja" game. A series of pieces of flying fruit will be launched on the canvas, and the player's job is to cut each of them (by dragging the mouse across them) before it falls off the bottom of the canvas. When a piece of fruit is sliced, it breaks into smaller pieces (shrapnel) which fall through the air. The player earns a point for each piece of fruit successfully sliced, and the game ends once 3 pieces of fruit fall off the canvas unsliced.

The project as described above would form a basic, playable version of the game. If time permits, additional features such as multiple levels, bombs, bonus points for drags that hit multiple pieces of fruit, images of fruit instead of simple circles, and other features to be determined will be implemented.

This project will bring together many of the topics we have studied this semester. The main program will be a WindowController class that creates the user interface. It will use the standard Objectdraw mouse event handler for mouse drags. There will also be at least one JButton and a listener for that button's events. Several ActiveObjects will control the creation of flying fruit objects, the animation of an individual flying fruit, and the animation of the fruit shrapnel that forms after a piece of fruit is sliced. An ArrayList will be used to track the pieces of fruit that are flying through the air at any given time.


By 4:00 PM, Tuesday, April 26, 2016, you are to submit (by email or in hard copy) a detailed design of your program, similar to those required for some of the lab assignments this semester. The design should list all of the classes that will make up your program, clearly indicating the purpose of each and if it is a "special" class like a WindowController or an ActiveObject. Include a list of the major instance variables you will use in each class and the methods you will need to implement. For each method, clearly indicate its parameters and return type and give a brief description of what the method will do and how it will do it. If any of your classes will involve the layout of graphical objects on the canvas, include drawings labelled with important coordinates and dimensions.

A sample design for the Fruit Ninja example follows.

The Fruit Ninja implementation will consist of 4 classes. One is a WindowController extension that manages the main game play. The other three are ActiveObject extensions that manage the creation of and animation of flying fruit, and the animation of the fruit shrapnel that is created when a piece of fruit is successfully sliced.

The game proceeds as follows. Each time the user presses the button to launch more flying fruit, an active object is created that in turn creates a series of flying fruit. The player attempts to drag the mouse over each flying fruit object to earn a point. If they do not do so before it falls off the bottom of the canvas, a miss is recorded. When 3 misses are recorded, the game ends.

An outline of each class follows:

public class FruitNinja extends WindowController implements ActionListener {

    // how many fruits can you miss before the game ends?
    private static final int MAX_MISSES = 3;
    // instance variables to keep track of scoring
    private JLabel scoreLabel;
    private int score, misses;
    // the game keeps a list of FlyingFruit objects currently in the air
    private ArrayList<FlyingFruit> fruitList;

    public void begin() {
        // set up GUI, create fruitList

    // handle button press
    public void actionPerformed(ActionEvent e) {

        // if game is not over
            // create FruitLauncher responsible for launching a series of
            // FlyingFruit objects

    // method to inform the game that there's a new FlyingFruit
    // in the air to check in our drag
    public synchronized void newFruit(FlyingFruit f) {


    // method to inform the game that a piece of fruit is done, either
    // because the fruit was hit or it went off the canvas, as indicated 
    // by the second parameter
    public synchronized void fruitDone(FlyingFruit f, boolean hit) {

       // if not a hit and game not over, record miss and update score
       // if game now over, display game over message
       // in all cases, remove f from fruitList


    // the only mouse event we care about is onMouseDrag, we simply loop over
    // all of the FlyingFruit objects currently in play and see if any of them
    // contain the point
    public void onMouseDrag(Location point) {

        // if game not over, loop over each flying Fruit
            // if it contains the point, send it the hit message,
            // record a point
        // update scoreboard
public class FruitLauncher extends ActiveObject {

    // we'll create between 3 and 7 FlyingFruits per FruitLauncher
    private static final int MIN_FRUITS = 3;
    private static final int MAX_FRUITS = 7;
    // in ms:
    private static final int AVERAGE_INTERVAL = 500;
    // just some information we need to remember from the parameters
    // to the constructor that need to be used in the run method, where
    // they are passed to the FlyingFruit constructor
    private DrawingCanvas c;
    private FruitNinja game;
    // constructor remembers a few bits of information then activates
    public FruitLauncher(FruitNinja game, DrawingCanvas c) {

        // remember things        
    // the life our our launcher is to decide how many to launch, then launch them
    public void run() {
        // choose number of fruits randomly
        // loop that many times, create a few FlyingFruit each time through
public class FlyingFruit extends ActiveObject {
    // lots of speeds and sizes
    private static final double MIN_XSPEED = -2;
    private static final double MAX_XSPEED = 2;
    private static final double MIN_YSPEED = -6;
    private static final double MAX_YSPEED = -10;
    private static final double FRUIT_SIZE = 40;
    private static final int SHRAPNEL_COUNT = 4;
    private static final double GRAVITY = 0.1;
    private static final int PAUSE_TIME = 33;
    // the actual graphical object that's flying
    private FilledOval fruit;
    // our speeds
    private double xSpeed, ySpeed;
    // need to remember the canvas
    private DrawingCanvas c;
    // reference to the game's WindowController which will be used
    // to report when new instances are created and when instances
    // fall off the bottom of the canvas
    private FruitNinja game;
    // have we hit this one yet?
    private boolean hit = false;
    // the constructor is responsible for remembering some information,
    // choosing a starting position and speed, and telling the game
    // that it exists.
    public FlyingFruit(FruitNinja game, DrawingCanvas c) {

        // remember parameters in instance variables 
        // our actual fruit object at random x position within middle
        // "half" of canvas, random color

        // calculate initial speed
        // tell the game that we have a new FlyingFruit
    // method to see if the fruit object here contains a point
    public boolean contains(Location point) {

    // method to call when this fruit object has been hit
    public void hit() {
    // the life of a FlyingFruit
    public void run() {

        // as long as still going, animate
            // move it
            // acceleration due to gravity
            // wait a little
            // see if we've gone off the bottom
            // if we've been hit, explode!
        // inform the game that this object is done, hit value indicates
        // hit or miss so game can update status

        // remove
public class Shrapnel extends ActiveObject {
    // animation parameters
    private static final double MAX_SPEED_CHANGE = 2;
    private static final double SHRAPNEL_SIZE = 20;
    private static final int PAUSE_TIME = 33;
    private static final double GRAVITY = 0.1;
    // instance variables for the actual graphical object, and its
    // animation speeds
    private FilledOval s;
    private double xSpeed, ySpeed;
    // we'll need this (or just its height) to decide when we've gone
    // off the bottom - using the canvas itself means things are still ok
    // if the canvas gets resized.
    private DrawingCanvas c;
    private static Random r = new Random();
    // construct our shrapnel
    public Shrapnel(double x, double y, double xSpeed, double ySpeed, 
                    Color color, DrawingCanvas c) {

        // remember parameters
        // create object        
        // choose a random speed similar to current speed

    // the simple life of fruit shrapnel
    public void run() {

        // while not off the bottom of the canvas
           // move
           // pause
           // accelerate due to gravity
        // remove from canvas

Some Ideas

For a course such as this, where we deal with graphics and event driven programming for so much of the semester, final projects are often video games, but they do not have to be. Along those lines, the following are games that have been successfully implemented using Objectdraw graphics and/or Java Swing components.

You could also do a greatly enhanced version of a game we used as an example or implemented in a lab earlier this semester such as Pong, Breakout, or Furious Fowl. Again, there is no requirement that your project must be a video game. Even if it is, do not limit yourself to the above list by any means. Have a look at your favorite list of old Atari games or check for games in your favorite app store for lots of ideas.

Have fun and good luck!

Submitting Your Work

Before 4:00 PM, Thursday, May 5, 2016, submit your lab for grading. There are two things you need to do to complete the submission: (i) Upload a copy of your lab (a .7z or .zip file containing your project directory) to terescoj AT (ii) Demonstrate the execution of your programs for your instructor. (iii) Hand a printout of the Java files that make up the programming assignment to your instructor. (2 business day grace period for demos and printouts).


This assignment is worth 150 points, which are distributed as follows:

> FeatureValueScore
Proposal (10 points)
Proposal text description 5
Proposal list of programming constructs 5
Written Design (20 points)
Major constructs and their purposes specified 4
Major classes/variables specified 6
Method signatures 5
Detailed method descriptions 5
Program Design, Efficiency, Style (50 points)
Appropriate comments 10
Good variable/method names 5
Appropriate variable declarations 6
Good use of constants 5
Appropriate formatting 3
Good overall design (classes and methods) 10
Appropriate use of language constructs (e.g., collections) 7
Efficiency (e.g., not reconstructing objects unnecessarily) 4
Program Correctness (70 points)
Determined by Grading Contracts

Penalty for uncaught exceptions

up to 10
Total 150