-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathPetMap.java
More file actions
40 lines (32 loc) · 956 Bytes
/
PetMap.java
File metadata and controls
40 lines (32 loc) · 956 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 holding;
/**
* RUN:
* javac typeinfo/pets/*.java
* javac holding/PetMap.java && java holding.PetMap
* OUTPUT:
* {My Cat=Cat Molly, My Dog=Dog Ginger, My Hamster=Hamster Bosco}
* Dog Ginger
* true
* true
*/
import java.util.*;
import typeinfo.pets.*;
public class PetMap {
private static void print(Object obj) {
System.out.print(obj);
}
private static void println(Object obj) {
System.out.println(obj);
}
public static void main(String[] args) {
Map<String, Pet> petMap = new HashMap<String, Pet>();
petMap.put("My Cat", new Cat("Molly"));
petMap.put("My Dog", new Dog("Ginger"));
petMap.put("My Hamster", new Hamster("Bosco"));
println(petMap);
Pet dog = petMap.get("My Dog");
println(dog);
println(petMap.containsKey("My Dog"));
println(petMap.containsValue(dog));
}
}