Question

In: Computer Science

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 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.

☑ [EC+10] 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

Explanation:I have written all the classes ZooAnimal,Moose,Camel,Cow,Elephant and Harness as per the requirements mentioned.I have shown the the output of the program, please find the image attached with the answer.Please upvote if you liked my answer and comment if you need any modification or explanation.

//ZooAnimal class

public class ZooAnimal {
   protected String name;
   protected String primaryColor;

   public ZooAnimal() {
       super();
   }

   public ZooAnimal(String name, String primaryColor) {
       super();
       this.name = name;
       this.primaryColor = primaryColor;
   }

   public void moving() {
       System.out.println(name + " is moving");
   }

   public void sleeping() {
       System.out.println(name + " is sleeping");
   }

   public String getName() {
       return name;
   }
   public void setName(String name) {
       this.name = name;
   }
   public String getPrimaryColor() {
       return primaryColor;
   }
   public void setPrimaryColor(String primaryColor) {
       this.primaryColor = primaryColor;
   }

   @Override
   public String toString() {
       return "name=" + name + ", primaryColor=" + primaryColor;
   }

}

//Elephant class

public class Elephant extends ZooAnimal {

   protected boolean isWild;

   public Elephant() {
       super();
   }

   public Elephant(String name, String primaryColor, boolean isWild) {
       super(name, primaryColor);
       this.isWild = isWild;
   }

   public boolean isWild() {
       return isWild;
   }

   public void setWild(boolean isWild) {
       this.isWild = isWild;
   }

   @Override
   public String toString() {
       return "Elephant [" + super.toString() + ", isWild=" + isWild + "]";
   }

}

//Camel class

public class Camel extends ZooAnimal {

   public Camel() {
   }

   public Camel(String name, String primaryColor) {
       super(name, primaryColor);
   }

   public void eating() {
       System.out.println(name + " is eating");
   }

   @Override
   public String toString() {
       return "Camel [name=" + name + ", primaryColor=" + primaryColor + "]";
   }

}

//Moose class


public class Moose extends ZooAnimal {

   public Moose() {
       super();

   }

   public Moose(String name, String primaryColor) {
       super(name, primaryColor);
   }

   @Override
   public void sleeping() {
       System.out.println("Moose " + name + " is sleeping");
   }

   @Override
   public String toString() {
       return "Moose [name=" + name + ", primaryColor=" + primaryColor + "]";
   }

}

//Cow class

public class Cow extends Moose {
   protected boolean givesMilk;

   public Cow() {
   }

   public Cow(String name, String primaryColor, boolean givesMilk) {
       super(name, primaryColor);
       this.givesMilk = givesMilk;
   }

   public boolean isGivesMilk() {
       return givesMilk;
   }

   public void setGivesMilk(boolean givesMilk) {
       this.givesMilk = givesMilk;
   }

   @Override
   public String toString() {
       return "Cow [ name=" + name + ", primaryColor=" + primaryColor
               + ", givesMilk=" + givesMilk + "]";
   }

}

//Harness class

public class Harness {

   public static void main(String[] args) {
       Elephant elephant = new Elephant("Tommy", "black", false);
       System.out.println(elephant.toString());
       Moose moose = new Moose("Ratty", "gray");
       System.out.println(moose.toString());
       moose.moving();
       Camel camel = new Camel("Tora", "yellow");
       System.out.println(camel.toString());
       camel.eating();
       Cow cow = new Cow("Teeti", "white", true);
       System.out.println(cow.toString());
   }

}

Outputs:


Related Solutions

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...
Create a project plan on the game or application you are creating. Using java programming. The...
Create a project plan on the game or application you are creating. Using java programming. The project plan should include the following: A description of the game or application The IDE or game engine your plan to use to create the game or app and information on how you are going to develop the game or app If you choose to create a game, how are you going to approach the game design and game development process or if you...
This for Java Programming Write a java statement to import the java utilities. Create a Scanner...
This for Java Programming Write a java statement to import the java utilities. Create a Scanner object to read input. int Age;     Write a java statement to read the Age input value 4 . Redo 1 to 3 using JOptionPane
Introduction In this lab, we will look at various aspects of methods in Java programming such...
Introduction In this lab, we will look at various aspects of methods in Java programming such as passing arguments to a method, use of local variables, and returning a value from a method. Exercise-1: RainFall Statistisc(50 pts) Write a program that asks user the total rainfall for the last six months of two consecutive years and do the following: the total rainfall per year the average monthly rainfall (for two years) the month with the most rain (per year) You...
Model the following in JAVA PROGRAMMING : In a software engineering project we are developing software...
Model the following in JAVA PROGRAMMING : In a software engineering project we are developing software for a Real estate agency. The Real Estate Agency has these types of properties: Shops, Apartments and Villas. All properties have: Property Owner, Address, Property Purpose (Sale/Rent), Area (in m^2) and price. Model these in an inheritance hierarchy considering that: 1. Shops have these fields in addition to properties: Floor (int), Street view (boolean). 2. Apartments have these feilds in addition to properties: Floor,...
Java programming One of the most popular games of chance is a dice game known as...
Java programming One of the most popular games of chance is a dice game known as “craps,” which is played in casinos and back alleys throughout the world. The rules of the game are straightforward: A player rolls two dice. Each die has six faces. These faces contain 1, 2,3,4,5, and 6 spots. After the dice have come to rest, the sum of the spots on the two upward faces is calculated. If the sum is 7 or 11 on...
Python Programming: Scrambled Word Game Topics: List, tuple Write a scrambled word game. The game starts...
Python Programming: Scrambled Word Game Topics: List, tuple Write a scrambled word game. The game starts by loading a file containing scrambled word-answer pair separated. Sample of the file content is shown below. Once the pairs are loaded, it randomly picks a scrambled word and has the player guess it. The number of guesses is unlimited. When the user guesses the correct answer, it asks the user if he/she wants another scrambled word. bta:bat gstoh:ghost entsrom:monster Download scrambled.py (code featured...
Java Programming Write a program that displays the following pattern *                         *       &nbsp
Java Programming Write a program that displays the following pattern *                         *          *          * *          *          *          *          *          *          *          *          *          *          *          *             *          *          *          *          *                         *          *          *                                     * Printing Pattern A * ** *** **** ***** ****** ******* Printing Pattern B ******* ****** ***** **** *** ** * Printing Pattern C * ** *** **** ***** ****** *******
IN JAVA PROGRAMMING Write a complete Java program to do the following: a) Prompt the user...
IN JAVA PROGRAMMING Write a complete Java program to do the following: a) Prompt the user to enter the name of the month he/she was born in (example: September). b) Prompt the user to enter his/her weight in pounds (example: 145.75). c) Prompt the user to enter his/her height in feet (example: 6.5). d) Display (print) a line of message on the screen that reads as follows: You were born in the month of September and weigh 145.75 lbs. and...
IN JAVA PROGRAMMING Write a complete Java program to do the following: a) Prompt the user...
IN JAVA PROGRAMMING Write a complete Java program to do the following: a) Prompt the user to enter a six-digit integer. b) Take the integer and break it up into two pieces of three-digits each (make sure you keep the order of digits). c) Display each 3-digit piece on a separate line with a proper message before each piece. For example, if the user enters  450835 as the integer, then the program should display the following output: Right 3-digit piece: 835...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT