EECS2030 Test 4


Instructions

There is one programming question and three other questions.


Programming question

Implement the PictureBook class. A skeleton can be found here. The API can be found here. A jar with the Book class can be found here.


Other questions

Question 1

The UML diagram
denotes that (select the best answer)
A. Classes A and B are in the aggregation relation
B. Classes A and B are in the inheritance relation
C. Classes A and B are in the composition relation
D. Classes A and B are in the usage relation



Question 2

In a method that overrides a method of the super class, to invoke that method of the super class, one uses the keyword  



Question 3

Consider the following classes.

public class CreditCard
{
   private double balance;

   /**
    * Checks if the balance of this card is positive.
    *
    * @throws RuntimeException if the balance of this card is not positive.
    */
   public void checkPositive() throws RuntimeException
   {
      if (this.balance <= 0)
      {
         throw new RuntimeException("Balance is negative");
      }
   }
}

public class RewardCard extends CreditCard
{
   private int points;

   /**
    * Checks if the balance of this card is positive.
    *
    * @throws Exception if the balance of this card is not positive.
    */
   public void checkPositive() throws Exception
   {
      if (this.balance <= 0)
      {
         throw new Exception("Balance is negative");
      }
   } 
}
Point out what is wrong in the above code. ("Use this.getBalance() instead of this.balance" is not the answer.)