Solutions for those exercises.

Questions

  1. What is the keyword used to call the constructor from the base class?
  • this.
  • the name of the base class.
  • base
  • over
  • inherits

Problem

Consider the following diagram:

A UML diagram for the Room ⇽ ClassRoom class (text version)

Suppose you are given an implementation of the Room class, such that

    Room test = new Room("UH", 243);
    Console.WriteLine(test);

displays

UH 243
  1. Write an implementation of the ClassRoom class. Your ToString method should display the room’s building and number, in addition to whether it has AV set-up.

  2. Write a SameBuilding static method to be placed inside the Room class such that

    Office test1 = new Office("UH", 127, "706 737 1566");
    ClassRoom test2 = new ClassRoom("UH", 243, true);
    Office test3 = new Office("AH", 122, "706 729 2416");
    Console.WriteLine(Room.SameBuilding(test1, test2));
    Console.WriteLine(Room.SameBuilding(test2, test3));

    Would display “true” and “false”.