Question

In: Computer Science

Classwork Java Program A zoo is developing an educational safari game with various animals. You will...

Classwork

Java Program

A zoo is developing an educational safari game with various animals. You will write classes representing Elephants, Camels, and Moose.  

Part A

Think through common characteristics of animals, and write a class ZooAnimal.

ZooAnimal should have at least two instance variables of different types (protected), representing characteristics that all animals have values for.  

It should also have at least two methods for behaviors that all animals do; these can simply print out a String stating what the animal is doing. (accessors and mutators are not behaviors).

Include at least one parameterized constructor.

Part B

Create classes Elephant, Camel, and Moose, all of which extend ZooAnimal. In each, include a default constructor that calls the parameterized superclass constructor.  

To one class (of Elephant, Camel, and Moose), add another instance variable specific to that type of animal. To another, add another behavior method. In a third, override a behavior from ZooAnimal.   

Part C

Create a test harness for the animal classes. In a main create at least one Elephant, Camel, and Moose, and show which behavior methods are usable for each.

Create another animal class inheriting from one of your three types (doesn't have to be zoologically accurate, but should make some sense), and either add an instance variable or add or override a method. This class should also be tested in the harness.

Solutions

Expert Solution

Here is the code for above problem statement along with outout screenshot. Please comment if need any further clarifications. Also do upvote if i answered your question.

-----------------------------------ZooAnimal----------------------------------

/**
* The Class ZooAnimal.
*/
public class ZooAnimal {
  
   /** The weight. */
   protected double weight;

   /** The category. */
   protected String category;

   /**
   * Instantiates a new zoo animal.
   *
   * @param weight the weight
   * @param category the category
   */
   public ZooAnimal(double weight, String category) {
       this.weight = weight;
       this.category = category;
   }

   /**
   * Eat.
   */
   public void eat() {
       System.out.println(this.category + " is eating");
   }

   /**
   * Walk.
   */
   public void walk() {
       System.out.println(this.category + " is walking");
   }

   /**
   * Gets the weight.
   *
   * @return the weight
   */
   public double getWeight() {
       return weight;
   }

   /**
   * Sets the weight.
   *
   * @param weight the new weight
   */
   public void setWeight(double weight) {
       this.weight = weight;
   }

   /**
   * Gets the category.
   *
   * @return the category
   */
   public String getCategory() {
       return category;
   }

   /**
   * Sets the category.
   *
   * @param category the new category
   */
   public void setCategory(String category) {
       this.category = category;
   }

}

-----------------------------------Elephant---------------------------------------

/**
* The Class Elephant.
*/
public class Elephant extends ZooAnimal {

   /**
   * Instantiates a new elephant.
   */
   public Elephant() {
       super(12, "Elephant");
   }
  
   public Elephant(String elephantType) {
       super(12, elephantType);
   }

   /**
   * Drink.
   */
   public void drink() {
       System.out.println("Elephant is drinking");
   }
}

------------------------------------Camel----------------------------------------

/**
* The Class Camel.
*/
public class Camel extends ZooAnimal {
  
   /** The camel type. */
   private String camelType;

   /**
   * Instantiates a new camel.
   */
   public Camel() {
       super(10, "Camel");
   }

   /**
   * Gets the camel type.
   *
   * @return the camel type
   */
   public String getCamelType() {
       return camelType;
   }

   /**
   * Sets the camel type.
   *
   * @param camelType the new camel type
   */
   public void setCamelType(String camelType) {
       this.camelType = camelType;
   }

}

-------------------------------------Moose--------------------------------------

/**
* The Class Moose.
*/
public class Moose extends ZooAnimal {
  
   /**
   * Instantiates a new moose.
   */
   public Moose() {
       super(15, "Moose");
   }

   /**
   * Walk.
   */
   public void walk() {
       System.out.println("Overridden : Moose is walking");
   }
}

----------------------------------AfricanElephant------------------------------

/**
* The Class AfricanElephant.
*/
public class AfricanElephant extends Elephant {
  
   public AfricanElephant() {
       super("African Elephant");
   }

   /**
   * Drink.
   */
   public void drink() {
       System.out.println("African Elephant is drinking");
   }
}

----------------------------------TestClassZoo------------------------------

/**
* The Class TestClassZoo.
*/
public class TestClassZoo {

   /**
   * The main method.
   *
   * @param args the arguments
   */
   public static void main(String[] args) {
       Elephant elephant = new Elephant();
       elephant.eat();
       elephant.walk();
       elephant.drink();
       AfricanElephant africanElephant = new AfricanElephant();
       africanElephant.eat();
       africanElephant.walk();
       africanElephant.drink();
       Camel camel = new Camel();
       camel.eat();
       camel.walk();
       Moose moose = new Moose();
       moose.eat();
       moose.walk();
   }

}

----------------------------------------------OUTPUT-------------------------------------------------


Related Solutions

JAVA programming A zoo is developing an educational safari game with various animals. You will write...
JAVA programming A zoo is developing an educational safari game with various animals. You will write classes representing Elephants, Camels, and Moose. Part A: Think through common characteristics of animals, and write a class ZooAnimal. ☑ ZooAnimal should have at least two instance variables of different types (protected), representing characteristics that all animals have values for. ☑ It should also have at least two methods for behaviors that all animals do; these can simply print out a String stating what...
Problem specifications: You are tasked with developing a complete temperature conversion program in Java. Your program...
Problem specifications: You are tasked with developing a complete temperature conversion program in Java. Your program should: -prompt the user with the following menu: -1-Convert Fahrenheit to Celcius -2-Convert Celcius to Fahrenheit -3-Quit Program The menu must be coded in its own method. -If user select option 1 then call a method that prompts the user to enter a value in degrees Fahrenheit and return it back to main. -call a method that converts from Fahrenheit to Celcius -call a...
Java guessing game: For this program you will use Linear Search. - Ask the user to...
Java guessing game: For this program you will use Linear Search. - Ask the user to choose between a number from 0 to 2000. - The user will guess how long the linear search will take in nanoseconds, - After the user puts in their answer, show the user the difference between the actual answer and their answer. (Example: The user puts in 5 nanoseconds. The actual time is 11 nanoseconds. The program will show 6 nanoseconds.) There should be...
Develop a Java program for the question below: A running race among animals: In a race...
Develop a Java program for the question below: A running race among animals: In a race among animals different types of animals are differenciated wih their running styles. In each iteration of the race, each participating animal makes a move acording to its style of running. Total length of the racecourt is NTotal (store this variable properly in the test class). Determine the winner animal and completion time of the race using polymorphism. Each of these animal classes extends from...
Java Project Requirements: 1.Write a Java program that plays a word game with a user. The...
Java Project Requirements: 1.Write a Java program that plays a word game with a user. The program asks the user questions and then creates a paragraph using the user’s answers. 2.The program must perform the following: a.Uses a Scanner object to ask the user: (The program asks for no other information) i.Full Name (First and Last name only) - stores this Full Name in one String object variable. ii.Age – must be read in as an int. iii.Profession or expected...
1.Create full program in Java that will simulate a Rock Paper Scissors Game You will create...
1.Create full program in Java that will simulate a Rock Paper Scissors Game You will create the code so that when the program is run the user will see in the console the following: We are going to play rock paper scissors. Please choose 1 for Rock 2 for Paper or 3 for scissors. The program will have your choice which is the integer-valued typed in by the user and compChoice which will be the randomly generated value of either...
Write a Java program that plays the game Rock, Paper, Scissors. The program should generate a...
Write a Java program that plays the game Rock, Paper, Scissors. The program should generate a random choice (Rock, Paper or Scissors) then ask the user to choose Rock, Paper or Scissors. After that the program will display its choice and a message showing if the player won, lost or tied. Next, the program should prompt the user to play again or not. Once the player selects to stop playing the game, the program should print the number of wins,...
Create a simple dice game in Java. Add screenshots and the program here.
Create a simple dice game in Java. Add screenshots and the program here.
JAVA PROGRAM, Create the game "Rock, Scissor, Paper": Make the AI pick randomly. You need to...
JAVA PROGRAM, Create the game "Rock, Scissor, Paper": Make the AI pick randomly. You need to look up Random numbers in Java. First ask the user what language they want to play in. Choice 1 is English, but choice 2 can be whatever real language you want. Your first loop is making sure they enter good input. If there is a tie you don't give them the option to play again. They have to. Outer loop runs until they say...
write on eclipse java Write a program named lab5 that will play a game of Blackjack...
write on eclipse java Write a program named lab5 that will play a game of Blackjack between the user and the computer. Create a second class named Card with the following: Define the following private instance variables: cardValue (int) & cardSuite (String) Write a constructor with no parameters that will Set cardValue to a random number between 1 and 13 Generate a second random number between 0 and 3 and assign cardSuite a string based on its value (0 –...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT