Homework 10
Designing Classes 

powered by FreeFind

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.

    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. 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. Open a Command prompt window.
    2. Change to the project directory using a command similar to:
      • cd \C201\Projects\Hw10
    3. At IUS enter:
      • v:\common\user\b438\forjava
      • java -cp . Game
    4. Print the game screen as it is being played.

Turn in

  1. First Page - Contains your name, date and Homework 10. Staple all pages together.
  2. Test, Game, Player, Room, Item and CommandWords class source listing
  3. Terminal Window printouts of a-f.