Homework 9
Designing Classes

Modified

SI - Next session will give additional discussion of Homework 9.

Overview - The purpose of the homework is to provide practice in code reuse and refactoring. In the class diagram at right, a Player and Test class have been added, and the Game class has been simplified by moving Room responsibility to the Player class.

Getting started

Assignment

  1. Create a Test class to help in testing.

    Test by:

    Should the game not quit properly after testing, you will not be able to compile.

    • Save the project, exit, and restart BlueJ or,
    • Reset Machine by pressing Ctrl+Shift+R.
       
  2. Refactor the project to add a separate Player class.

    A Player object has responsibility for the player's current room.

    Test by:

  3. When the player quits, automatically display the path followed throughout the game.

    Test by:

     

  4. Add the back command. This command does not have a second word. Entering the back command takes the player into the previous room.

    Test Game class by:

    Test Test class by:

  5. Refactor the back command to move repeatedly back until the beginning room is reached.

    Hints:

    Test by:

     

  6. Add to the Game class the method main() so that the program can be run outside of BlueJ. The method follows:
     
       public static void main(String args[])
      {
          ( new Game() ).play();
      }

    Test:

    1. Compile in BlueJ.
       
    2. Open a Command prompt window.

      Start | Programs | Accessories | Command Prompt

    3. Change to the project directory using a command similar to:
      • cd \Users\username\blueJ\Hw10
         
    4. To execute the Game, enter:
      • java Game
         
    5. Capture the game screen as it is being played and paste to a Word file.

Turn in

C201 OnCourse Dropbox - Create a HW9 folder in the C201 OnCourse DropBox. Copy the following:

  1. Test, Game, Player and CommandWords class JAVA files.
  2. A Word file with Terminal Window printouts of a-e and Command Prompt Window of f.