24 lines
621 B
Java
Raw Normal View History

2015-04-20 15:36:01 -07:00
//: holding/PetMap.java
import typeinfo.pets.*;
import java.util.*;
import static net.mindview.util.Print.*;
public class PetMap {
public static void main(String[] args) {
2015-05-05 11:20:13 -07:00
Map<String,Pet> petMap = new HashMap<>();
2015-04-20 15:36:01 -07:00
petMap.put("My Cat", new Cat("Molly"));
petMap.put("My Dog", new Dog("Ginger"));
petMap.put("My Hamster", new Hamster("Bosco"));
print(petMap);
Pet dog = petMap.get("My Dog");
print(dog);
print(petMap.containsKey("My Dog"));
print(petMap.containsValue(dog));
}
} /* Output:
2015-05-05 11:20:13 -07:00
{My Cat=Cat Molly, My Dog=Dog Ginger, My Hamster=Hamster Bosco}
2015-04-20 15:36:01 -07:00
Dog Ginger
true
true
*///:~