OnJava8-Examples/typeinfo/PetCount4.java

23 lines
638 B
Java
Raw Normal View History

2015-09-07 11:44:36 -06:00
// typeinfo/PetCount4.java
2015-06-15 17:47:35 -07:00
import typeinfo.pets.*;
import onjava.*;
2015-06-15 17:47:35 -07:00
public class PetCount4 {
public static void main(String[] args) {
TypeCounter counter = new TypeCounter(Pet.class);
for(Pet pet : Pets.createArray(20)) {
2015-11-03 12:00:44 -08:00
System.out.print(pet.getClass().getSimpleName() + " ");
2015-06-15 17:47:35 -07:00
counter.count(pet);
}
2015-11-03 12:00:44 -08:00
System.out.println();
System.out.println(counter);
2015-06-15 17:47:35 -07:00
}
2015-09-07 11:44:36 -06:00
}
/* Output:
2015-06-15 17:47:35 -07:00
Rat Manx Cymric Mutt Pug Cymric Pug Manx Cymric Rat
EgyptianMau Hamster EgyptianMau Mutt Mutt Cymric Mouse Pug
Mouse Cymric
{Rodent=5, Cat=9, Cymric=5, Manx=7, Hamster=1, Mouse=2,
Pug=3, Dog=6, Rat=2, Pet=20, EgyptianMau=2, Mutt=3}
2015-09-07 11:44:36 -06:00
*/