1 |
ic02 |
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" |
ic02: Interface vs. Inheritance
ready? | assigned | due | points |
---|---|---|---|
false | Thu 02/01 11:00AM | Thu 02/01 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.)
This worksheet is practice at understanding interface vs. inheritance.
For this worksheet, you need the additional
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 and assuming the methods appear inside this class:
public class TraderBobs {
// methods appear here
}
|
- (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.
-
(15 pts)
public static void TB07 () { FreeCandy s = new FreeCandy(25); System.out.println("s: " + s.getName()); }
-
(15 pts)
public static void TB08 () { Edible t = new FreeCandy(30); System.out.println("t: " + t.getPrice()); }
-
(15 pts)
public static void TB09 () { Product u = new Product(299,"Ziploc Bags"); System.out.println("u: " + u.getName()); }
-
(15 pts)
public static void TB10 () { Product v = new FreeCandy(30); System.out.println("v: " + v.getCalories()); }