CS 1401, Exam #3

Date: Tuesday, April 5, 2005
Class section (9:00-10:20 am or 10:30-11:50 am): ______________________
Name (please type legibly, ideally in block letters): ______________________________________________________________________
UTEP ID # (if you do not remember it, it is OK): ______________________________________________________________________

All of the construction activity on the corner of University Avenue and Oregon Street is for the purpose of building a new hotel.  Let us name this new hotel The Miner’s Cave.

Question 1.  Designing with Inheritance.   Consider the following problem statement:

All hotel rooms in The Miner’s Cave have a room number, one or more beds, and one or more bathrooms.  There are three different types of rooms in this hotel, based upon floor plan and features:  standard rooms, family rooms, and business rooms.  Standard rooms have a floor plan consisting of one basic room with a bathroom.  All family rooms contain a microwave oven and small refrigerator.  Family rooms are available in two different floor plans:  family suite rooms and family loft rooms.  Each family suite room has two bedrooms and two bathrooms.  Each family loft room has two floors, arranged with a sofa bed and bathroom downstairs, plus another bed and bathroom upstairs.  Business rooms are designed for the business traveler who may be staying for a longer period of time.  Business rooms have a separate living room area with a large desk and high-speed network connection, a separate bedroom, and a kitchenette complete with appliances and dishes. 

 (a)  Draw the inheritance hierarchy.  


(b)  Write a CRC card for the class FamilyRoom.  (It is not necessary to list responsibilities.)






Question 2.  File Objects and Looping Statements  


The hotel manager would like to know the average number of rooms rented per night for the month of September.  The number of rooms rented for different nights in September is written in a file rooms.txt, with one night per line.  Write a code segment using a while loop that will read in the number of rooms rented for all the nights listed in the file and find the average number of rooms rented per night. Your code should work for a file of any size, and should display a text message stating the average.  For example, if the file contained only 5 lines, representing the number of rooms rented for each of 5 nights, it might appear as follows:






The total for all 5 nights is 85 rooms, and the average is 17 rooms rented per night.  The message displayed would be as follows: 

The average number of rooms rented per night in September was 17.  






Question 3.  Implementing Derived Classes

The Miner’s Cave is designing a database for employee records.  Read the following problem statement and the code below.  The provided code defines a superclass Employee.  On the blank sheet of paper you have been given, write the code for the subclass  ManagerEmployee ONLY.  For this subclass, include a class definition header, any instance variables needed, and a constructor taking three arguments.  Also, override any superclass method that must be implemented in a different way within the subclass.  

All employees of the hotel have a name and a five-digit employee number.  There are two basic groups of employees:  manager employees, and hourly employees.  Manager employees have a title assigned indicating their level, either “general manager” or “assistant manager.”  In addition, the manner in which pay is computed is different for the manager employees than the hourly employees.  Manager employees receive a base amount (which may vary) plus a defined percentage of the hotel revenues (revenues will vary also).  If a manager employee is a general manager, the formula for computing pay is the base amount plus 4% of revenues.  If a manager employee is an assistant manager, the formula for computing pay is the base amount plus 2% of revenues.  Hourly employees are paid at an hourly rate per hour.  

 public class Employee 
        private String name;
        private int employeeNum;

        public Employee ( String inName, int inNum )
              name = inName;
              employeeNum = inNum

        public String getName( )
             return name;

        public int getNum( )
            return employeeNum;

       // “set” methods are omitted, and you may ignore them

        // Compute pay using two double parameters.
        public double computePay ( double a , double b )
            return  a  * b;      // General formula


Question 4. Event-Driven Input and Output (GUI)

Two versions of the same display window are presented below.  The windows are part of a GUI for an online reservation application for the hotel.   UTEP students/faculty/staff as well as corporate guests receive special rates on hotel rooms.  The "Before" version of the window below shows how the window first appears, before the user has done anything.  The "After" version of the same window, shown beneath the first one, shows how the window appears after the user has submitted a UTEP or corporate id number.  In the "After" version, the system responds with a message thanking the user and informing the user that the room availability and price information will be displayed next.  

"Before" Version

"After" Version


Refer to the separate handout you were given to answer the questions that follow.  Most of the code needed to create the display window show above is printed on your handout.  However, some of the lines of code are missing.

(a)  Which layout manager was used to create this window?  Write the code needed to create and initialize the layout manager in the space below.  Write an "A" on the handout to show where this code should be placed.


(b)  The code for one of the components in the window is missing from the handout.  Write the code needed to create and initialize it in the space below.  Write a "B" on the handout to show where this code should be placed.  


(c)  Write the line of code to cause the component you defined in (b) above to be displayed in the window with the other components.  Write a "C" on the handout to show where this code should be placed.


(d)  What should be the last statement in the main method in this example?  Write the code for this statement below.  Write a "D" on the handout to show where this code should be placed.


Question 5. Extra Credit


Refer to the handout in Question 4 to answer this question.  Write the needed line(s) of code to complete the following tasks, and write the letter "E" (plus "F", and so on, if you need to place the lines of code in different places) on the handout to show where the code should be placed:

a) Create a new integer variable.

b) Retrieve whatever the user typed as input for the UTEP or corporate number, and assign that input to your variable.