CS 101 (Spring 1999)
Quiz 7: ADTs and Subclassing

Quiz Posted
(Wednesdays)
Given in class
(Wednesdays)
17 Mar 24 Mar

Information about quizzes:

The questions are intended to be straightforward. If you keep up with the material in the class, almost no preparation may be necessary. The Collaboration Policy allows you to study in groups for the quizzes, but you are on your own when you take the quiz.

You will fare better on the quiz if you try working the problems before looking at the solutions. If you don't understand the question or its answer, please get help.

  1. With reference to Lab 3, write the class StockList (from scratch) that represents a list of stocks.
  2. Same as Exercise 1, but this time implement StockList by extending the generic List.java.
  3. Add to the Exercise 2 StockList the method Stock getStock() that returns the stock contained in a list item.
  4. Add to the Exercise 3 StockList the method StockList getRest() that returns the rest of the list.
  5. Consider the class
    public class Rectangle {
       protected int length, width;
       protected Rectangle() {
          length = 0;
          width  = 0;
       }
       public Rectangle(int length, int width) {
          this.length = length;
          this.width  = width;
       }
       public int area()      { return length * width;     }
       public int perimeter() { return 2*length + 2*width; }
    }
    

    Write a class for a Square by extending this class.

  6. Write the class MisguidedDealer that behaves just like your Dealer from Lab 6, except that a misguided dealer takes a card if and only if a real dealer would not.

[ solution ]


Last modified 22:41:42 CST 16 March 1999 by Ron K. Cytron