Monday, February 27, 2012

Lab 14: Undead

Everyone is a Person. But, as you know, this set is divided into the Living and the Undead.
  • The Civilian and the Slayer are are all Living.
  • Zombie, Vampire and Ghost all belong to the Undead
For this lab you will implement all these classes and in the given inheritance hierarchy. You will also implement the appropriate methods so that when you run this main on your program:
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? false
Finally, 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:

jmvidal said...

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.