2.9  Example: Definition of the class hierarchy that represents tourist attractions

A hotel has information for the guests about several kinds of attractions in the city. These can be museums, shows, and restaurants. For each of these attractions, they have the name, the location and the phone number. For restaurants there is also the information about the kind of food they serve and the price range (cheap, moderate, expensive). For each show the hotel has the show title and the time the show starts. For the museum, the available information describes the kind of museum (aquarium, natural history, a gallery, etc.) and the hours when it is open. Write a data definition for these classes.

/*
                         +---------------+     +-------+               
                         | Attraction    |  +->| Posn  |                 
                         +---------------+  |  +-------+           
                         | String name   |  |  | int x |            
                         | Posn Location |--+  | int y |           
                         | String phone  |     +-------+             
                         +---------------+                         
                                / \                                
                                ---                                
                                 |                                 
         -----------------------------------------------           
         |                     |                       |           
  +-------------+    +-------------------+    +-----------------+  
  | Museum      |    | Restaurant        |    | Show            |  
  +-------------+    +-------------------+    +-----------------+  
  | String kind |    | String foodType   |    | String showName |  
  | int opens   |    | String priceRange |    | int startTime   |  
  | int closes  |    +-------------------+    +-----------------+  
  +-------------+                                                  
*/

// to describe a city tourist attraction
abstract class Attraction {
  String name;
  Posn Location;
  String phone;
}

// to describe a museum
class Museum extends Attraction {
  String kind;
  int opens;
  int closes;

  Museum(String name, Posn Location, String phone, 
         String kind, int opens, int closes) {
    this.name = name;
    this.Location = Location;
    this.phone = phone;
    this.kind = kind;
    this.opens = opens;
    this.closes = closes;
  }
}

// todescribe a restaurant
class Restaurant extends Attraction {
  String foodType;
  String priceRange;

  Restaurant(String name, Posn Location, String phone, 
             String foodType, String priceRange) {
    this.name = name;
    this.Location = Location;
    this.phone = phone;
    this.foodType = foodType;
    this.priceRange = priceRange;
  }
}

// to describe a show
class Show extends Attraction {
  String showName;
  int startTime;

  Show(String name, Posn Location, String phone, 
       String showName, int startTime) {
    this.name = name;
    this.Location = Location;
    this.phone = phone;
    this.showName = showName;
    this.startTime = startTime;
  }
}

// We leave it to the reader to add the examples of instances