Homework 10
Designing Classes

Modified

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

Overview - The purpose of the homework is to provide practice in responsibility-driven design and use of collections, specifically HashMaps. In the class diagram at right, an Item class has been added to support a room that contains items and a player that can carry items.

An item has a name for identification and weight. For example, an item could be a soda with a weight of 500 grams.

A room can contain any number of items but only one of a particular item (i.e. only one soda).

A player can take items from the current room they are in or drop items in the room.

Getting started

Assignment

  1. Create an Item class that has responsibility for the item data.

    Test by:

     

  2. The Room class is to be extended to hold multiple Items. Room class will still have responsibility for all room data; a room description, room exits and, now, room items. Examine the exits field as a model.

    Positive test by:

    Negative test by:

     

  3. The Player class is to be extended to have responsibility for the player to carry any number of items. The class diagram should appear as at right after the extension of Player.

    Positive test by:

    Negative test by:

     

  4. The Game is to be extended for the new commands take and drop. These commands have a second word, the name of the item, similar to the go command.

    Test Game class by:

    Test Test class by:

  5. (Extra credit) Implement an item command that prints out all the items carried by the player and the total weight.
     
  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 HW10 folder in the C201 OnCourse DropBox. Copy the following:

  1. Test, Game, Player, Room, Item and CommandWords JAVA files.
  2. A Word file with Terminal Window printouts of a-f.