1
Handout A
for
h07
CS56 W20

Beverage.java

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
public class Beverage extends Product implements Edible {

    private int calories;
    private double fluidOunces;
    
    public Beverage(int price, String name, 
		int calories, double fluidOunces) {
	super(price, name);
	this.calories = calories;
	this.fluidOunces = fluidOunces;
    }

    public int getCalories() {return this.calories;}
    public double getFluidOunces() {return this.fluidOunces;}
}

Edible.java

1
2
3
4
5
/** something that can be eaten */
@FunctionalInterface 
public interface Edible {
    public int getCalories();
}

Food.java

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
public class Food extends Product implements Edible {

    private int calories;
    private double weight;
    
    public Food(int price, String name, 
		int calories, double weight) {
	super(price, name);
	this.calories = calories;
	this.weight = weight;
    }

    public int getCalories() {return this.calories;}
    public double getWeight() {return this.weight;}
}

Code for

TraderBobs problem

Note: FreeCandy and Product are on Handout B.

End of Handout