CSE1030 Lab 04

Tue Oct 15 and Thu Oct 17
Due: Mon Oct 21 before 11:59PM

Introduction

The purpose of this lab is to implement two classes that use composition; one class is also a singleton. Both classes may appear again in Lab 06 (graphical user interfaces).

Question 1: Implement a Boggle™ die class

Boggle™ is a word game played with 16 dice each having 6 faces labelled with a letter of the English alphabet. One die has a face labelled with the string QU to reflect the fact that Q is usually followed by U in English words.

To start a game of Boggle™, the dice are placed in a dome that covers the game board and the dice are shaken to randomize where each dice appears on the board and to randomize which face is up on each dice. The game board is simply a 4-by-4 grid.

After shaking the dice and making sure that each die has settled into one of the grid positions, the board is placed down and the dome removed. A 3-minute timer is started. The players then search the assortment of letters to find English words made up of three or more letters. Words are formed from letters that adjoin horizontally, vertically, or diagonally with no die being used more than once per word. The image to the left shows an example of how the word QUESTIONS can be formed. Other words that can be formed include EASE, EAST, NOISES, QUEST, and QUESTION.

The longest words that can be formed have 17 letters; the image to the left shows how INCONSEQUENTIALLY can be formed.

In this lab, you are asked to implement two classes: one class represents a Boggle™ die; the other class is a partial representation of the game of Boggle™ (namely, the 16 dice).

In eclipse:

  1. Create a new Java Project (perhaps called lab4)
  2. In your project, create a new Package called cse1030.games
  3. Complete the class BoggleDie so that it implements the following API:
  4. Complete the class Boggle so that it implements the following API: Note that Boggle is a singleton class. Starter code for the Boggle class can be found at the end of this web page.

For BoggleDie you may use the Die class from Lab 1 (i.e., BoggleDie is a composition of a Die and some other stuff). A Die has faces numbered 1 through 6, whereas a BoggleDie has faces with a letter or letters "A" through "P", "QU", and "R" through "Z". Thus, your BoggleDie implementation will need to maintain a mapping from numbers 1 through 6 to the letters on the faces of the die. The Die class API and Java source file can be found at the links below:

2013-10-19: A JUnit unit tester is available for BoggleDie.

submit 1030 L4 Boggle.java BoggleDie.java

Boggle starting code

package cse1030.games;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * A singleton class representing a game of Boggle. The instance
 * has 16 <code>BoggleDie</code> references that represent the
 * standard dice used in Boggle. 
 * 
 * @author CSE1030_F_13_14
 *
 */
public class Boggle {  
  /**
   * The letters on the 16 boggle dice.
   */
  private static final String[] LETTERS = { "AAEEGN", "ELRTTY", "WAOOTT",
      "ABBJOO", "EHRTVW", "CIMOTU", "DISTTY", "EIOSST", "YDELRV", "ACHOPS",
      "UHIMNQ", "EEINSU", "EEGHNW", "AFFKPS", "HLNNRZ", "XDEILR" };

  /**
   * The singleton instance.
   */
  private static final Boggle INSTANCE = new Boggle();

  /**
   * The 16 boggle dice.
   */
  private List<BoggleDie> dice;
  
  /**
   * Constructs the instance by creating a collection of of
   * the 16 standard boggle dice.
   * 
   */
  private Boggle() {
    
    
  }
  
  /**
   * Returns the single <code>Boggle</code> instance.
   * 
   * @return the single <code>Boggle</code> instance
   */
  public static Boggle getInstance() {
    
    
  }
  
  /**
   * Returns a list of the 16 dice in their current state. The order
   * of dice is guaranteed to be stable between calls to
   * <code>shuffleAndRoll</code>.
   * 
   * <p>
   * Clients are unable to modify the game dice using
   * the returned list; i.e., modifying the returned list has no effect on
   * the dice held by the singleton.
   * 
   * @return
   */
  public List<BoggleDie> getDice() {
    
    
  }
  
  /**
   * Randomly shuffles the order of the dice and rolls all of dice.
   * This simulates the shaking of the dice in the physical version
   * of the game.
   */
  public void shuffleAndRoll() {
    
    
  }
}