Handout

https://ucsb-cs56-f17.github.io/exam/e01/cs56_f16_e01_practice_c/handout/

CODE FOR QUESTION 1

Handout for practice exam question: https://ucsb-cs56-f17.github.io/exam/e01/cs56_f16_e01_practice_c

Product.java

1
2
3
4
5
6
7
	/** something that can be sold */
public abstract class Product {

/** get the price (in cents) */
public abstract int getPrice();

}

Shippable.java

1
2
3
4
5
6
	/** something that can be shipped */
public interface Shippable {

/** get the shipping weight in pounds */
public double getWeight();
}

Book.java

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
/** A Book */
public class Book extends Product implements Shippable {

private int price;
private double weight;
private String author;
private String title;

public Book(String author, String title, int price,
double weight) {
this.author = author;
this.title = title;
this.price = price;
this.weight = weight;
}

public int getPrice() {return this.price;}
public String getTitle() {return this.title;}
public String getAuthor() {return this.author;}
public double getWeight() {return this.weight;}
}

Song.java

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
/** A downloadable Song */
public class Song extends Product {

private int price;
private String artist;
private String title;

public Song(String artist, String title, int price) {
this.artist = artist;
this.title = title;
this.price = price;
}

public Song(String artist, String title) {
this(artist,title,99);
}

public int getPrice() {return this.price;}
public String getTitle() {return this.title;}
public String getArtist() {return this.artist;}

}