Lecture 23 Objectives [Dec 07]prev next

ART MOMENT: .
 
Lady Warwick and Her Son
Artist: John Singer Sargent (1856-1925)
Date: 1905
   

With student id, museum tickets cost only $8


At the end of today's class you should

HAVE READ:

KNOW:

BE ABLE TO:

DAILY QUESTION:


Sample Exam question(s)

  1. You have been asked to write a Stack class. This Stack will have methods push(String s), String pop(), and empty() which (respectively, push a String onto the stack, pop a String from the stack, and check if the stack is empty.

    Your co-worker suggests that you make Stack extend ArrayList, as follows:


    1a) Describe a weakness of this approach and the problems it would cause.
    1b) Describe a better approach where the Stack class uses an ArrayList, rather than extends it.
     
  2. Which design diagram is best suited for the following problem description:

A course taught at WPI is taught by a single professor and has a number of students enrolled in that course. There are two types of courses: Undergraduate courses (seven weeks long) and graduate courses (14 weeks long).

(A) (B)
(C)

 

(D)

Ans: The arrow with a Triangle describes the inheritance relationship. For example, in Choice A, it shows that class UndergradCourse is a derived class of Course. A Straight line between two classes represents an association, which is either (one::one, one::many, or many::many).

Now, choice D describes a situation where a professor teaches any number of courses, each of which can have a number of students; note that these students themselves may each be in any number of courses [not restricted to just a single course]. Note also that each course is restricted to being taught by a single professor. Finally, there are two types of students -- graduate students and undergraduate students.

Choice C suggests that the Course be a derived class from two base classes. However, in Java, we know that there can only be single inheritance, so this choice is discarded.

Choice B seems to state that a Course is a type of Professor; we discard this one

Choice A describes how a professor teaches a single course, and that course is taught by a single professor. In this class there can be any number of students, but each student belongs to exactly a single class. There are two types of classes: undergraduate and graduate classes.

Now that we have described each of these, the one that seems most related is choice A. Why? Because choice B & C are discarded and choice D creates different types of Students, while the problem is asking us to consider different types of courses.