Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Java Create four classes: 1. An Animal class that acts as a superclass for Dog a

ID: 3573903 • Letter: J

Question

Java

Create four classes:

1.      An Animal class that acts as a superclass for Dog and Bird

2.      A Bird class that is a descendant of Animal

3.      A Dog class that is a descendant of Animal

4.      A “driver” class named driver that instantiates an Animal, a Dog, and a Bird object.

The Animal class has:

·        one instance variable, a private String variable named   name

·        a single constructor that takes one argument, a String, used to set the instance variable, then prints the message

The Animal (its name) has been created.”

·        “getter” and “setter” methods for the instance variable name

·        a no-argument method named sleep that prints the message

The Animal (its name) is asleep.

·        a no-argument method named makeNoise that prints the message

The Animal (its name) is making a noise.

·        a toString method that returns

The Animal (its name)”.

·        an equals method that compares another Object to this Animal object by comparing their names. Use our “improved” version of the equals method.

Notice that there are NO references to either the Dog or the Bird class in the Animal class.

The Bird class:

·        extends the Animal class

·        has no instance variables

·        has a single constructor that takes one argument, a String used to set the instance variable of its parent, then prints the message

A Bird (its name) has been created.”

·        has a no-argument method named makeNoise that prints the message

The Bird (its name) is chirping.

·        has a toString method that returns

The Bird (its name)”.

·        has an equals method that compares another Object to this Bird object by comparing their names. Use our “improved” version of the equals method.

The Dog class:

·        extends the Animal class

·        has one instance variable, a private String named breed.

·        has a single constructor that takes two arguments, a String used to set the instance variable of its parent, and another String used to set the instance variable of this object (breed). It also prints the message

A Dog (its name) of breed (its breed) has been created.”

·        has “getter” and “setter” methods for the instance variable   breed

·        has a no-argument method named makeNoise that prints the message

The Dog (its name) is barking.

·        has a toString method that returns

The Dog (its name) of breed (its breed)”.

·        has an equals method that compares another Object to this Dog object by comparing their names and breeds. Use our “improved” equals method.

The driver class contains a main method which:

·        creates an Animal object with a name “Oscar”.

·        creates a Dog object with a name “Inka” and a breed “Mutt

·        creates a Bird object with a name “Tweety

·        uses the toString method to print Oscar, Inka, and Tweety

·        causes Oscar, Inka, and Tweety each to make a noise

·        causes Oscar, Inka, and Tweety each to go to sleep

Answer the following questions below:

1.      What is/are the names of the base classes?

2.      What is/are the names of the derived classes?

3.      Does Animal have a parent class? If so, what is its name?

4.      Is the method toString() overridden? Is makeNoise? Is sleep?

5.      Using the new-and-improved version of equals, can you test if Oscar and Inka are equal?

6.      Do any of your classes belong to a package? If so, what is the name of that package?

7.      If you made all instance variables protected instead of private, do you need getters and setters to access them?

Explanation / Answer

1. base class is Animal

2. derived classes are Bird, Dog

3. No

4. methods toString and makeNoise are overridden. but method sleep is not overridden.

*****************END*************PLS GIVE ME GOOD RATING*****************************

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote