CSC234 - Project 3
TopSpin - Array


Overview

In this project, you will implement the TopSpin puzzle from Binary Arts, now known as ThinkFun. We will first be using arrays to create our implementation. Your implementation will act like the puzzle above.

TopSpin Interface

public interface TopSpin {

    // Shift the pieces one space to the left
    public void shiftLeft();

    // Shift the pieces one space to the right
    public void shiftRight();

    // Reverses the pieces currently inside the spin mechanism, such that
    // the first and last are swapped, etc.
    public void spin();

    // Returns true if the puzzle is solved, such that the pieces are in numerical order.
    public boolean isSolved();

    // Retrieves the number in the ith spot of the cycle
    public int get(int i);
    
    // Either shift left, right, or spin the object for moves times
    public void mixup(int moves);
    
}

Your implementation below should have a constructor that creates the TopSpin object with size numbers, and a spin mechanism of spinSize.

    public TopSpin(int size, int spinSize)

Your numbers should start at 1. size must be at least 1, and spinSize must be less than or equal to size, otherwise, an InvalidTopSpinException should be thrown.

Array Implementation

Your first implementation of the TopSpin interface should use an array as the basis of the TopSpin game. Devise an efficient implementation based on what we have studied about queues, stacks and lists, each of which generally included additional integer components to track the state of the collection. This class will be written in the ArrayTopSpin.java.

InvalidTopSpinException

This exception is needed for the constructor of your TopSpin implementations. It should inherit from RunTimeException and have an empty body.

Eclipse

Download the skeleton project for TopSpin and import it into Eclipse to begin.

What to turn in

  1. ArrayTopSpin.java

© Mark Goadrich 2009, Centenary College of Louisiana