Person. But, as you know, this set is divided into the Living and the Undead. - The
Civilianand theSlayerare are allLiving. Zombie,VampireandGhostall belong to theUndead
public static void main(String[] args) {
Zombie z1 = new Zombie("Keith Richards");
Vampire v1 = new Vampire("Angel");
Ghost g1 = new Ghost("Bloody Mary");
Civilian c1 = new Civilian("Rick Grimes");
Civilian c2 = new Civilian("Glenn");
Slayer s1 = new Slayer("Buffy Summers");
Person[] people = {z1, v1, g1, c1, c2, s1};
//Tell me, are you living or undead.
for (Person p: people){
p.alive();
}
System.out.println("-----------------------------");
//OK now, say Hi
for (Person p: people){
p.sayHi();
}
System.out.println("------------------------------");
Civilian c3 = new Civilian("Keith Richards");
//a Person equals any other person with the same name
System.out.println("Is Keith's zombie equal to Keith? " + z1.equals(c3));
//except Ghosts, they are not equal to anything,
//not even themselves.
System.out.println("Aye you equal to yourself? " + g1.equals(g1));
System.out.println("Are you equal to Rick? " + g1.equals(c1));
}you get the following output: I am Undead. I am Undead. I am Undead. I am Living. I am Living. I am Living. ----------------------------- arrgh....braaaains..... Hi, I am Angel, a vampire. ......... Hello, I am Rick Grimes Hello, I am Glenn Buffy Summers here, just saving the world, again. ------------------------------ Is Keith's zombie equal to Keith? true Aye you equal to yourself? false Are you equal to Rick? falseFinally, your
Person, Living and Undead classes should be abstract.You will turn in all your .java files (remember, there is one for each class) at the dropbox.cse.sc.edu.

1 comment:
The line
System.out.println("Is Keith's zombie equal to Keith? " + z1.equals(c3));
used to say
System.out.println("Is Keith's zombie equal to Keith? " + z1.equals(c2));
which was not what I wanted. It is now correct.
Keith's zombie should be equal to Civilian Keith since they both have the same name.
Post a Comment