Question

Your job is to do the following: build a Monster class as your base class, along...

Your job is to do the following: build a Monster class as your base class, along with two derived classes, Undead and Animal. All Monsters have names and origins. Undead monsters have the year their heart stopped beating. Animals have a species. Your Undead class should be extended to create a Zombie class and a Vampire class. Your Animal Class will extend to include a Werewolf class. Zombies have a favorite weapon, Vampires have a number of humans they have feasted on, and Werewolves have the number of days until their next transformation.

In addition to the attributes above, each class should contain a related speak() and diet() method which prints the monster’s favorite saying and food to standard output, i.e. – zombies say “UUUGGGHHH” (duh) and eat brains.

To convince yourself that polymorphisms works on your demonic creations, in your main method (MosterDrive Class) you should create an ArrayList (called monsterList) of Monsters, and populate the list with 10 instances of Zombies, Vampires, and Werewolves. After you create the list, call Collections.shuffle(monsterList) so that you no longer have any idea where each type of monster is in the list. Your main method will then loop through the ArrayList and for each instance: 1) Print the monster’s name 2) Print the specific type of Monster using the instanceof operator 3) Call the speak() and diet() method on the instance. 4) Display the favorite weapon of zombies, the number of humans a vampire has feasted on, and the number of days until a Werewolf transforms.

I need help to make this in java language.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

import java.util.ArrayList;
import java.util.Collections;

class Monster{
   private String name;
   private String origin;
   Monster(String n,String o){
       this.name=n;
       this.origin=o;
   }
   public String getName() {
       return name;
   }
   public void setName(String name) {
       this.name = name;
   }
   public String getOrigin() {
       return origin;
   }
   public void setOrigin(String origin) {
       this.origin = origin;
   }
   void to_String() {
      
   }
  
}
class Undead extends Monster{
   int year;
   Undead(String n, String o,int y) {
       super(n, o);
       this.year=y;
   }
  
}
class Animal extends Monster{
   String species;
   Animal(String n, String o,String s) {
       super(n, o);
       this.species=s;
   }
  
}
class Zombie extends Undead{
   String weapon;
   Zombie(String n, String o, int y,String w) {
       super(n, o, y);
       this.weapon=w;
      
   }
   String speak() {
       return("UUUGGGHHH");
   }
   String diet() {
       return("Eat brains");
   }
   void to_String() {
       System.out.println("Name: "+super.getName()+"\t Type: "+super.getClass()+"\t Speak: "+this.speak()+"\t Diet: "+this.diet()+"\t Weapon: "+this.weapon);
   }
}
class Vampire extends Undead{
   int noOfHumans;
   Vampire(String n, String o, int y,int h) {
       super(n, o, y);
       this.noOfHumans=h;
   }
   String speak() {
       return("GRAAAAAAAAAAH");
   }
   String diet() {
       return("Human blood");
   }
   void to_String() {
       System.out.println("Name: "+super.getName()+"\t Type: "+super.getClass()+"\t Speak: "+this.speak()+"\t Diet: "+this.diet()+"\t No of humans feasted: "+this.noOfHumans);
   }
}
class Werewolf extends Animal{
   int noOfDays;
   Werewolf(String n, String o, String s,int d) {
       super(n, o, s);
       this.noOfDays=d;
   }
   String speak() {
       return("OWWOOOOOOOOOOOOOO");
   }
   String diet() {
       return("Deer");
   }
   void to_String() {
       System.out.println("Name: "+super.getName()+"\t Type: "+super.getClass()+"\t Speak: "+this.speak()+"\t Diet: "+this.diet()+"\t No of days for transformation: "+this.noOfDays);
   }
}
public class MonsterDrive {

   public static void main(String[] args) {
       ArrayList<Monster> m=new ArrayList<Monster>();
       m.add(new Zombie("Z1","O1",1923,"axe"));
       m.add(new Zombie("Z2","O2",1924,"stone"));
       m.add(new Zombie("Z3","O3",1925,"stone"));
       m.add(new Zombie("Z4","O4",1926,"axe"));
       m.add(new Zombie("Z5","O5",1927,"gun"));
       m.add(new Zombie("Z6","O6",1928,"axe"));
       m.add(new Zombie("Z7","O7",1929,"gun"));
       m.add(new Zombie("Z8","O8",1933,"axe"));
       m.add(new Zombie("Z9","O",1934,"axe"));
       m.add(new Zombie("Z10","O10",1936,"stone"));
  
       m.add(new Vampire("V1","O1",1923,1));
       m.add(new Vampire("V2","O2",1924,4));
       m.add(new Vampire("V3","O3",1925,5));
       m.add(new Vampire("V4","O4",1926,6));
       m.add(new Vampire("V5","O5",1927,4));
       m.add(new Vampire("V6","O6",1928,7));
       m.add(new Vampire("V7","O7",1929,8));
       m.add(new Vampire("V8","O8",1933,9));
       m.add(new Vampire("V9","O",1934,3));
       m.add(new Vampire("V10","O10",1936,2));
      
       m.add(new Werewolf("W1","O1","Canis lupus",5));
       m.add(new Werewolf("W2","O2","Canis lupus",10));
       m.add(new Werewolf("W3","O3","Canis lupus",8));
       m.add(new Werewolf("W4","O4","Canis lupus",2));
       m.add(new Werewolf("W5","O5","Canis lupus",8));
       m.add(new Werewolf("W6","O6","Canis lupus",9));
       m.add(new Werewolf("W7","O7","Canis lupus",1));
       m.add(new Werewolf("W8","O8","Canis lupus",10));
       m.add(new Werewolf("W9","O9","Canis lupus",13));
       m.add(new Werewolf("W10","O10","Canis lupus",14));
      
       Collections.shuffle(m);
      
       for(int i=0;i<m.size();i++) {
           m.get(i).to_String();;
       }
   }

}


//############################# ########################################

OUTPUT
########

Add a comment
Know the answer?
Add Answer to:
Your job is to do the following: build a Monster class as your base class, along...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • HELP....ITS CLOSING TONIGHT INFSCI 0017 – Assignment 4 You are doing an internship in a company...

    HELP....ITS CLOSING TONIGHT INFSCI 0017 – Assignment 4 You are doing an internship in a company specialized in create role-­‐playing computer games. As a part of the programming team, you are asked to implement and test the first version of a RolePlayer class. In the game, a RolePlayer is a knight with the mission of fight and kill monsters: vampires and werewolves. As the player defeat monsters, he/she gains points. The player is considered trainee if he/she has less than...

  • 1-Suppose you write an application in which one class contains code that keeps track of the...

    1-Suppose you write an application in which one class contains code that keeps track of the state of a board game, a separate class sets up a GUI to display the board, and a CSS is used to control the stylistic details of the GUI (for example, the color of the board.) This is an example of a.Duck Typing b.Separation of Concerns c.Functional Programming d.Polymorphism e.Enumerated Values 2-JUnit assertions should be designed so that they a.Fail (ie, are false) if...

  • Prompt: In this stepping stone lab assignment, you will build a Recipe class, getting user input...

    Prompt: In this stepping stone lab assignment, you will build a Recipe class, getting user input to collect the recipe name and serving size, using the ingredient entry code from Stepping Stone Lab Four to add ingredients to the recipe, and calculating the calories per serving. Additionally, you will build your first custom method to print the recipe to the screen. Specifically, you will need to create the following:  The instance variables for the class (recipeName, serving size, and...

  • can you solve it in java please Create the following: 1. Class Invoice ( the node...

    can you solve it in java please Create the following: 1. Class Invoice ( the node ) that includes three instance variables:     int No; // the Invoice No             String CustName; // the Customer name             int Amount; // the Invoice Amount Invoice next; // points to the next Invoice Default and overloaded constructors 2. Class Shop that includes three instance variables: Invoice head; Invoice Tail; Your class should have the following: • A method that initializes the instance variables....

  • Part 1: Song Class Write the code for the Song class. 1. Instance variables: title:String, lyrics:String,...

    Part 1: Song Class Write the code for the Song class. 1. Instance variables: title:String, lyrics:String, numAwards:int 2. For the 2-arg constructor (parameters are title and lyrics), use the following default value: - numAwards: 3 3. Create the 3-argument constructor. 4. No additionalconstructors. 5. Generate all getters and setters for instance variables 6. toString: Return a nicely formatted string describing this object 7. toSummary: This instance method will return a String that contains up to the first 10 characters of...

  • Write the code for the Song class. 1. Instance variables: title:String, lyrics:String, numAwards:int 2. For the...

    Write the code for the Song class. 1. Instance variables: title:String, lyrics:String, numAwards:int 2. For the 2-arg constructor (parameters are title and lyrics), use the following default value: - numAwards: 3 3. Create the 3-argument constructor. 4. No additionalconstructors. 5. Generate all getters and setters for instance variables 6. toString: Return a nicely formatted string describing this object 7. toSummary: This instance method will return a String that contains up to the first 10 characters of the lyrics. Be sure...

  • *** FOR A BEGINNER LEVEL JAVA CLASS, PLEASE KEEP CODE SIMPLE, AND WE USE BLUE J...

    *** FOR A BEGINNER LEVEL JAVA CLASS, PLEASE KEEP CODE SIMPLE, AND WE USE BLUE J IN CLASS (IF IT DOESNT MATTER PLEASE COMMENT TELLING WHICH PROGRAM YOU USED TO WRITE THE CODE, PREFERRED IS BLUE J!!)*** ArrayList of Objects and Input File Use BlueJ to write a program that reads a sequence of data for several car objects from an input file. It stores the data in an ArrayList<Car> list . Program should work for input file containing info...

  • Using your Dog class from earlier this week, complete the following: Create a new class called...

    Using your Dog class from earlier this week, complete the following: Create a new class called DogKennel with the following: Instance field(s) - array of Dogs + any others you may want Contructor - default (no parameters) - will make a DogKennel with no dogs in it Methods: public void addDog(Dog d) - which adds a dog to the array public int currentNumDogs() - returns number of dogs currently in kennel public double averageAge() - which returns the average age...

  • Amusement Park Programming Project Project Outcomes Use the Java selection constructs (if and if else). Use...

    Amusement Park Programming Project Project Outcomes Use the Java selection constructs (if and if else). Use the Java iteration constructs (while, do, for). Use Boolean variables and expressions to control iterations. Use arrays or ArrayList for storing objects. Proper design techniques. Project Requirements Your job is to implement a simple amusement park information system that keeps track of admission tickets and merchandise in the gift shop. The information system consists of three classes including a class to model tickets, a...

  • Java using data structures The objective is to create your own Hash Table class to hold...

    Java using data structures The objective is to create your own Hash Table class to hold a list of employees and their ID numbers. I've provided the TableEntry class which will be each data object in the hash table. The list of employees will be provided as a .txt file and must be read with the code. please create a .txt file called Employees.txt with the info provided so that the java code can read it in. Employees.txt: (No WhiteSpace...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT