1
ic01
CS56 W18
Name:
(as it would appear on official course roster)
Umail address: @umail.ucsb.edu section
4pm, 5pm or 6pm
Optional: name you wish to be called
if different from name above.
Optional: name of "homework buddy"
(leaving this blank signifies "I worked alone"

ic01: Interface vs. Inheritance

ready? assigned due points
true Tue 01/30 11:00AM Tue 01/30 12:15PM

You may collaborate on this homework with AT MOST one person, an optional "homework buddy".

MAY ONLY BE TURNED IN IN THE LECTURE/LAB LISTED ABOVE AS THE DUE DATE,
OR IF APPLICABLE, SUBMITTED ON GRADESCOPE. There is NO MAKEUP for missed assignments;
in place of that, we drop the four lowest scores (if you have zeros, those are the four lowest scores.)


  1. (10 pts) Please fill in the information at the top of this homework sheet, including your name and umail address. Put the time your discussion section starts (4pm, 5pm or 6pm) in the space indicated (the one you are registered for—even if you usually attend a different one.) If the other two items apply, please fill them in as well. Please do this every single time you submit homework for this class.
  2. This worksheet is practice at understanding interface vs. inheritance. For this worksheet, you need the additional [handout A](handout_a/) with code for these files: `Beverage.java`, `Edible.java`, `Food.java`, `FreeCandy.java` and `Product.java`. These are classes used by a grocery store known as "Trader Bobs". Some of these methods will compile and run, while others will not. Indicate, for each method, where it compiles or not, and if it does compile, the output when invoked. in context of the classes on [handout A](handout_a/) and assuming the methods appear inside this class: ```java public class TraderBobs { // methods appear here } ```
    Will it compile?Output when called (only if it compiles)
    Yes
    No

    (15 pts)

      public static void TB01 () {
        Beverage m = new Beverage(99,"Coke",150,12.0);
        System.out.println("m: " + m.getCalories());
      }
    
  3. (15 pts)

      public static void TB02 () {
        Beverage n = new Edible(199,"Gummi Bears",520,5);
        System.out.println("n: " + n.getPrice());
      }
    
  4. (15 pts)

      public static void TB03 () {
        Edible o = new Beverage(89,"Diet Coke",0,12.0);
        System.out.println("o: " + o.getFluidOunces());
      }
    

    Continued from previous problems… follow same instructions as on page 1.

  5. (15 pts)

      public static void TB04 () {
         Edible p = new Food(249,"Kind Bar",200,1.4);
         System.out.println("p: " + p.getCalories());	
      }
    
  6. (15 pts)

      public static void TB05 () {
         Edible q = new Edible(149,"Snickers",245,1.56);
         System.out.println("q: " + q.getCalories());
      }
    
  7. (15 pts)

      public static void TB06 () {
           Food r = new Food(99,"Almonds",100,0.63);
           System.out.println("r: " + r.getName());
      }