-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRegistry.java
More file actions
40 lines (31 loc) · 743 Bytes
/
Copy pathRegistry.java
File metadata and controls
40 lines (31 loc) · 743 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 com.twenis.prototype;
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("Basic Movie");
movie.setPrice(24.99);
movie.setRuntime("2 hours");
items.put("Movie", movie);
Book book = new Book();
book.setNumberOfPages(335);
book.setPrice(19.99);
book.setTitle("Basic Book");
items.put("Book", book);
}
}