CS 1401 Assignment #8 

Date Assigned: Monday, October 20 or Tuesday, October 21, 2008.

Due Dates:   Both electronic and printed versions of your work must be submitted according to the following schedule:

·         Electronic version: The electronic version must be emailed to your TA by 11:59 p.m. Sunday, October 26 (for MWF labs), or by 11:59 p.m. Monday, October 27, 2008 (for TR labs).  Attach source code file(s).

·         Printed version:  A printout of your assignment must be handed in to your TA at the beginning of your lab section the following day, either Monday, October 27 (for MWF labs), or Tuesday, October 28, 2008 (for TR labs).

Objective: The main objective of this assignment is to learn how to learn to design user-defined classes and ADTs. Make sure you turn in your assignment, both electronic and printed versions, on time even if unfinished.  Partial credit will be given for incomplete assignments turned in on time.  A significant late penalty will apply if printed versions are not turned in at the beginning of lab.  Failure to submit electronic versions on time will result in NO CREDIT for the assignment.  If your program does not compile, you will receive NO CREDIT.  If it does not compile, do not delete problem statements; keep all the statements in your program so that you may receive as many points as possible, but comment out statements as necessary in order for your program to compile successfully.

 

Programming assignment: In this lab you will practice object-oriented design technique as you define a Room class and use this class to create (instantiate) individual Room objects.  For the basic version of this lab, write separate code for this assignment and incorporates parts of previous labs as needed.  It is not necessary to add this lab content to last week’s assignment, and you do not have to implement classes with looping or progress from room to room unless you wish to do so (see Extra Credit below for more details). 

 

Each Room should have the following data attributes supplied when the Room is created:

·         Room number

·         Name of the room (for example, “Dr. Novick’s office”)

·         Main research area of the professor

·         Number of gold nuggets awarded for the correct research area answer

 

You should provide these details as input parameters to the constructor method for Room.  The Room objects will also need to know adjacent (“neighboring”) room numbers to the north, south, east, and west.  These numbers may be defined within the constructor method in order to avoid an excessive number of constructor parameters for this lab.  If there is no adjacent room in a particular direction, set the room number for that direction to -1.

 

For each of the data attributes, you should define the following methods:

·         Accessor (“get”) method

·         Mutator (“set”) method  (exceptions are room number and adjacent rooms; they won’t be changing after they are set)

 

In addition, you should write the following additional methods for the Room class:

·         A “quizResearchArea()” method which takes as input a string, compares the string to the correct research area, and returns an integer value of  gold nuggets (the number awarded if there is a match, or 0 nuggets for no match).  This method can be called from the “quizPlayer()” method in the application program.   

·         A version of toString() method which returns a String containing explanatory text and the value of all data attributes for the Room object (such as room number, name of room, etc.)

 

Finally, the Room class should have a static variable such as “currentRoom” to use for the current room.

 

Your Task: Write a small version of the MinerQuest program.  At the beginning of the program, create at least five room objects, including one that belongs to a professor so that the research area may be quizzed.  Include the usual displays as before: welcome the player; prompt the player to enter his/her name; explain the player’s mission; and display valid player input “moves,” which are represented by single characters as defined in previous labs.  However, for this lab the player will remain in one room, a professor’s office.  Display the current room. Call the quizPlayer()” method for that room, allowing a certain number of tries to enter the correct answer, as before.  Display the result and total number of gold nuggets as in previous labs.  In addition, call the “toString()” method and display the data attributes for ALL rooms that you defined.  

 

  

 

Expanded CS Building Map (not drawn to scale)

 
 Dr. Novick’s Office
Room 243 (Hallway
Segment)
Dr. Ward’s Office

 

Dr. Mondave’s Office

 

Dr. Fuentes’s Office

 

 
Room 242 (Hallway

Segment)

Room 209 (Martha’s Office)

 

Room 241 (Foyer)

Room 0 (Front Entrance)

 

Room 234 (Dept. Office)

 

 

Room 231 (Dept. Chair’s Office)

 

 

 
 
Homework assignment: on a separate sheet of paper, solve Ex. 6 from p. 520 

Deliverables: as instructed by your TA.

Extra Credit:  Add the use of the Room class to your game implementation from the last lab, complete with looping and progress from room to room.  Define the variables for adjacent offices as Room objects themselves.