Question

Please help me with the following question. This is for Java programming. In this assignment you are going to demonstrate the uses of inheritance and polymorphism. You will create an Animals class and...

Please help me with the following question. This is for Java programming.

In this assignment you are going to demonstrate the uses of inheritance and polymorphism. You will create an Animals class and a Zoo class that holds all the animals. You should create a general Animalclass where all other classes are derived from (except for the Zoo class). You should then create general classes such as Mammal, Reptile, and whatever else you choose based off of the Animalclass. For example, the Mammal class will hold things related to mammals like fur, warm blooded, etc. From these classes you should then create specific classes such as Tiger (based off the Animalclass) or Lizards which would be based off of the Reptile class and so on. Because some properties these classes will not apply to all subclasses, you will need to override these properties. For example, say you create a Bird class that is derived off the Animal class and then derive a Penguinclass off the Bird class. Your Bird class may have a fly property in it, but Penguins don't fly. You would want to override that property so that your Penguin class doesn't inherit the fly property from the Bird class.

Your class must satisfy the following requirements:

  • Your program must be menu driven and allow the user to perform at a minimum the following functions:
    • Add specific animals to the class
    • Remove/delete animals from the class
    • Display all the animals in the class
    • Display a specific animal in the class by name and a random one
    • Display a specific animals by type (e.g., display all the tigers, or penguins, or grey elephants).
  • Your program must contain the following classes at a minimum:
    • Zoo
    • Animal
    • 3 subclass derived off Animal like Reptile, Mammal, etc. or alternate classes like Biped, Quadruped or some other unique way that you think of classifying animals and that can be solidified into a class.
    • 9 specific types of animals that derive from the Reptile, Mammal, or whatever subclasses you have that are derived from the Animal class.
  • Each of your classes should include a member function to represent the class member data as a string.
  • The Zoo class will hold Animals. It is the main program and should have member functions to add or remove the Animals and a function to represent the entire Zoo as a string. It should also have functions to get a specific Animal (by name) and an operator to get a random one from the Zoo.
  • Your main program should create instances of specific Animals and then populate the Zoo with them. The user should then be allowed to view the properties of specific Animals that they request or from one that is chosen at random.
  • Create test cases to thoroughly test your program. Your test cases should show the input and expected output for each case.
0 0
Add a comment Improve this question Transcribed image text
Answer #1


public class Animal {
  
   String move;
   void show()
   {
       System.out.println("Animal class");
   }
  
}
class Reptiles extends Animal
{
String type;
  
   void show()
   {
       System.out.println("Reptiles class");
   }
  
}
class Turtle extends Reptiles
{
   Turtle(String type,String move)
   {
       this.move=move;
       this.type=type;
   }
   void show()
   {
       System.out.println("type: "+type+" move: "+move);
   }
}


class Crocodile extends Reptiles
{
   Crocodile(String type,String move)
   {
       this.move=move;
       this.type=type;
   }
   void show()
   {
       System.out.println("type: "+type+" move: "+move);
   }
}
class Snake extends Reptiles
{
   Snake(String type,String move)
   {
       this.move=move;
       this.type=type;
   }
   void show()
   {
       System.out.println("type: "+type+" move: "+move);
   }
}
class Bird extends Animal
{
  
   String color;
   String swim;
   void show()
   {
       System.out.println("Bird class");
   }
  
}
class Parrot extends Bird
{
   Parrot(String move,String color)
   {
       this.move=move;
       this.color=color;
   }
   void show()
   {
       System.out.println("move : "+move +"color :"+color);
   }
}
class Penguin extends Bird
{
   Penguin(String color,String move)
   {
       this.move=move;
       this.color=color;
   }
   void show()
   {
       System.out.println("move : "+move +"color :"+color);
   }
}
class Duck extends Bird
{
   Duck(String color,String swim,String move)
   {
       this.move=move;
       this.swim=swim;
       this.color=color;
   }
   void show()
   {
       System.out.println("Swim : "+swim +" color :"+color+" move:"+move);
   }
}
class Mammals extends Animal
{
   String type;
  
   void show()
   {
       System.out.println("Mammals class");
   }
}
class Tiger extends Mammals
{
   Tiger(String type,String move)
   {
       this.move=move;
       this.type=type;
   }
   void show()
   {
       System.out.println("type: "+type+" move: "+move);
   }
}


class Buffalo extends Mammals
{
   Buffalo(String type,String move)
   {
       this.move=move;
       this.type=type;
   }
   void show()
   {
       System.out.println("type: "+type+" move: "+move);
   }
}
class Dog extends Mammals
{
   Dog(String type,String move)
   {
       this.move=move;
       this.type=type;
   }
   void show()
   {
       System.out.println("type: "+type+" move: "+move);
   }
}
class Zoo
{
   public static void main(String args[])
   {
       Animal a=new Animal();
       Reptiles r=new Reptiles();
       Snake r1=new Snake("squamata","crawl");
       Reptiles r2=new Crocodile("crocodilians","crawl");
       Reptiles r3=new Turtle("turtles","walk");
       Mammals m=new Mammals();
       Mammals m1=new Tiger("Carnivore","walk");
       Mammals m2=new Dog("Omnivore","walk");
       Mammals m3=new Buffalo("Herbivore","walk");
       Bird b=new Bird();
       Bird b1=new Parrot("fly","green");
       Bird b2=new Penguin("black","walk");
       Bird b3=new Duck("white","walk","yes");
       r.show();r1.show();r2.show();r3.show();a.show();
       b.show();b1.show();b2.show();b3.show();
       m.show();m1.show();m2.show();m3.show();
      
        
   }
}
output:

Reptiles class
type: squamata move: crawl
type: crocodilians move: crawl
type: turtles move: walk
Animal class
Bird class
move : flycolor :green
move : walkcolor :black
Swim : walk color :white move:yes
Mammals class
type: Carnivore move: walk
type: Omnivore move: walk
type: Herbivore move: walk

Add a comment
Know the answer?
Add Answer to:
Please help me with the following question. This is for Java programming. In this assignment you are going to demonstrate the uses of inheritance and polymorphism. You will create an Animals class and...
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
  • Please help me with the following question. This is for Java programming. In this assignment you...

    Please help me with the following question. This is for Java programming. In this assignment you are going to demonstrate the uses of inheritance and polymorphism. You will create an Animals class and a Zoo class that holds all the animals. You should create a general Animalclass where all other classes are derived from (except for the Zoo class). You should then create general classes such as Mammal, Reptile, and whatever else you choose based off of the Animalclass. For...

  • Need help with this Java question in 1 hour please JAVA Using the files from the...

    Need help with this Java question in 1 hour please JAVA Using the files from the in-class assignment add two additional animals of your choice. For each animal add two additional methods appropriate to your particular animal. As the majority of the code for this program exists you will not need an algorithm. Use the 3 java classes below. Thank you //Animal.java public class Animal {    public Animal() {    System.out.println("A new animal has been created!");    }   ...

  • (The interface class-like) Assume you have the Edible interface with its abstract method. Design a class named Animal a...

    (The interface class-like) Assume you have the Edible interface with its abstract method. Design a class named Animal and its two subclasses named Mammal and Dairy. Make Sheep and Bear as subclasses of Mammal and make implement the Edible interface. howToEat() and sound() are the main two methods for all edible classes while sound() is the main method for the non-edible classes. 1. Draw the UML diagram for the classes and the interface 2. Use Arraylist class to create an...

  • Lab Assignment : In this lab, you are going to implement QueueADT interface that defines a...

    Lab Assignment : In this lab, you are going to implement QueueADT interface that defines a queue. Then you are going to use the queue to store animals. 1. Write a LinkedQueue class that implements the QueueADT.java interface using links. 2. Textbook implementation uses a count variable to keep track of the elements in the queue. Don't use variable count in your implementation (points will be deducted if you use instance variable count). You may use a local integer variable...

  • Exercise 8 (The interface class-like) Assume you have the Edible interface with its abstract method Design...

    Exercise 8 (The interface class-like) Assume you have the Edible interface with its abstract method Design a class named Animal and its two subclasses named Mammal and Dairy. Make Sheep and Bear as subclasses of Mammal and make Chicken and Cow as subclasses of Dairy. The Sheep and Dairy classes implement the Edible interface. howToEat) and sound() are the main two methods for all edible classes while sound() is the main method for the non-edible classes. 1. Draw the UML...

  • C++ Programming Assignment S Mammal Lab This lab's goal is to give you some practice using inheritance, virtual functions, pointers, dynamic memory allocation, random numbers, and polym...

    C++ Programming Assignment S Mammal Lab This lab's goal is to give you some practice using inheritance, virtual functions, pointers, dynamic memory allocation, random numbers, and polymorphism. To complete the lab implement the following steps: Create a class called Mammal. All mammals have a weight and a name, so its data should be the mammal's weight and name. Provide a default constructor that sets the mammal's weight to 0 and name to null, and another constructor that allows the weight...

  • PRG/421 Week One Analyze Assignment – Analyzing a Java™Program Containing Abstract and Derived Classes 1.    What is...

    PRG/421 Week One Analyze Assignment – Analyzing a Java™Program Containing Abstract and Derived Classes 1.    What is the output of the program as it is written? (Program begins on p. 2) 2. Why would a programmer choose to define a method in an abstract class (such as the Animal constructor method or the getName()method in the code example) vs. defining a method as abstract (such as the makeSound()method in the example)? /********************************************************************** *           Program:          PRG/421 Week 1 Analyze Assignment *           Purpose:         Analyze the coding for...

  • This is the question about object-oriend programming(java) please show the detail comment and prefect code of...

    This is the question about object-oriend programming(java) please show the detail comment and prefect code of each class, Thank you! This question contain 7 parts(questions) Question 1 Create a class a class Cat with the following UML diagram: (the "-" means private , "+" means public) +-----------------------------------+ | Cat | +-----------------------------------+ | - name: String | | - weight: double | +-----------------------------------+ | + Cat(String name, double weight) | | + getName(): String | | + getWeight(): double | |...

  • C# - Inheritance exercise I could not firgure out why my code was not working. I...

    C# - Inheritance exercise I could not firgure out why my code was not working. I was hoping someone could do it so i can see where i went wrong. STEP 1: Start a new C# Console Application project and rename its main class Program to ZooPark. Along with the ZooPark class, you need to create an Animal class. The ZooPark class is where you will create the animal objects and print out the details to the console. Add the...

  • Can you please pick Automobile For this assignment. Java Programming Second Inheritance OOP assignment Outcome: Student...

    Can you please pick Automobile For this assignment. Java Programming Second Inheritance OOP assignment Outcome: Student will demonstrate the ability to use inheritance in Java programs. Program Specifications: Programming assignment: Classes and Inheritance You are to pick your own theme for a new Parent class. You can pick from one of the following: Person Automobile Animal Based on your choice: If you choose Person, you will create a subclass of Person called Student. If you choose Automobile, you will create...

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