-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRegistry.java
More file actions
40 lines (30 loc) · 741 Bytes
/
Registry.java
File metadata and controls
40 lines (30 loc) · 741 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package exercises;
import java.util.HashMap;
import java.util.Map;
public class Registry {
private Map<String, Item> items = new HashMap<String, Item>();
public Registry() {
loadItems();
}
public Item createItem (String type) {
Item item = null;
try {
item = (Item)(items.get(type)).clone();
} catch(CloneNotSupportedException e) {
e.printStackTrace();
}
return item;
}
private void loadItems() {
Movie movie = new Movie();
movie.setTitle("Shutter Island");
movie.setPrice(99.99);
movie.setRuntime("3 hours");
items.put("Movie", movie);
Book book = new Book();
book.setTitle("Rich Dad Poor Dad");
book.setPrice(159.99);
book.setNumberOfPages(123);
items.put("Book",book);
}
}