Question

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

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?

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

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

Add a comment
Know the answer?
Add Answer to:
Java Create four classes: 1.      An Animal class that acts as a superclass for Dog 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
  • Java file Name Dog Classes and Methods Create a constructor that incorporates the type, breed, and...

    Java file Name Dog Classes and Methods Create a constructor that incorporates the type, breed, and name variables (do not include topTrick). Note: The type refers to what the breed typically does; for example, a corgi would be a “cattle herding dog.” A Shiba Inu would be a “hunting dog.” Create the setTopTrick() mutator method Dog is parent class Corgi and Driver are subclasses Complete the Corgi class: Using the UML Class diagram, declare the instance variables. Create the two...

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

  • In a project named 'DogApplication', create a class called 'Dog' 1. declare two instance variables in...

    In a project named 'DogApplication', create a class called 'Dog' 1. declare two instance variables in 'Dog' : name (String type) age (int type) 2. declare the constructor for the 'Dog' class that takes two input parameters and uses these input parameters to initialize the instance variables 3. create another class called 'Driver' and inside the main method, declare two variables of type 'Dog' and call them 'myDog' and 'yourDog', then assign two variables to two instance of 'Dog' with...

  • Write Python code to create a class called Dog which represents a dog. The Dog class...

    Write Python code to create a class called Dog which represents a dog. The Dog class should have properties of breed (i.e. what type of dog it is), name and weight. The class should also have a constructor that takes these parameters to initialise the dog object, and a method called bark that prints out the word 'Woof!' to the screen. After you have defined the Dog class, create a Dog object called goodDog with a breed of 'terrier', a...

  • JAVA :The following are descriptions of classes that you will create. Think of these as service...

    JAVA :The following are descriptions of classes that you will create. Think of these as service providers. They provide a service to who ever want to use them. You will also write a TestClass with a main() method that fully exercises the classes that you create. To exercise a class, make some instances of the class, and call the methods of the class using these objects. Paste in the output from the test program that demonstrates your classes’ functionality. Testing...

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

  • Implement a program that requests from the user a list of words (i.e., strings) and then...

    Implement a program that requests from the user a list of words (i.e., strings) and then prints on the screen, one per line, all four-letter strings in the list. >>> Enter word list: ['stop', 'desktop', 'top', 'post'] stop post An acronym is a word formed by taking the first letters of the words in a phrase and then making a word from them. For example, RAM is an acronym for random access memory. Write a function acronym() that takes a...

  • In Java Code Needed is Below the Question Using Program 3: Encapsulating Dogs, modify this program...

    In Java Code Needed is Below the Question Using Program 3: Encapsulating Dogs, modify this program to create a database of dogs of your own. You will also include File I/O with this program. You will create 3 classes for this assignment. The first class: Create a Class representing the information that is associated with one item (one dog) of your database. Name this class Dog. Using Lab 3, this will include the information in regard to one dog. The...

  • Java Problem 2: Employee (10 points) (Software Design) Create an abstract class that represents an Employee and contains abstract method payment. Create concrete classes: SalaryEmployee, CommissionEm...

    Java Problem 2: Employee (10 points) (Software Design) Create an abstract class that represents an Employee and contains abstract method payment. Create concrete classes: SalaryEmployee, CommissionEmployee, HourlyEmployee which extend the Employee class and implements that abstract method. A Salary Employee has a salary, a Commision Employee has a commission rate and total sales, and Hourly Employee as an hourly rate and hours worked Software Architecture: The Employee class is the abstract super class and must be instantiated by one of...

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