Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I will also be creating a 4th class with a main method, but I mainly need help with these first 3 classes as I feel

I will also be creating a 4th class with a main method, but I mainly need help with these first 3 classes as I feel like I am doing them wrong:

Animal class will have four instance variables (legs and eyes both integers) and (eat and sound both strings). All four will protected. You will have two constructors: one will accept no parameters and will have the four instance variables assigned to either 0 or nothing, appropriately. The other will accept four incoming parameters and will set the instance variables appropriately to the values of the incoming parameters. This class will also have a method called printAnimal that has no incoming parameters. It will simply print information about the current state (i.e. value) of each instance variable. For this print statement you must precede the string that you are going to print out with something like From Animal: to indicate that the printing is being conducted within the class Animal. This method will not return anything. Finally, there will be a method called setLegs that accepts one incoming parameter and will assign its value to the instance variable legs. This method will not return anything. You are now to do the following sequence of statements:

Spider class this will be a subclass (child) of the super class Animal (parent). No instance variables are declared. You will have two constructors: one will accept no parameters. The other will accept four incoming parameters. Both constructors will invoke the parent constructor (i.e. of the Animal class) appropriately. This class will also have a method called printAnimal that will override the method with the same name within the class Animal. This method will also have no incoming parameters. It will simply print information about the current state (i.e. value) of each instance variable. For this print statement you must precede the string that you are going to print out with something like From Spider: to indicate that the printing is being conducted within the class Spider. Also, this method must invoke the method printAnimal within the superclass/parent (i.e. Animal class). This method will not return anything. This class will have another method called getNumEyes that will have no incoming parameters but will return the value of the instance variable eyes. This class will have another method called setLegs that will accept one incoming parameter. This method will then set the value of the instance variable legs by calling its parents (i.e. Animal class) own method setLegs to do this task. This method will not return anything.

Lion class this will be a subclass (child) of the super class Animal (parent). No instance variables are declared. You will have one constructor: It will accept four incoming parameters. This constructor will invoke the parent constructor (i.e. of the Animal class) appropriately. This class will also have a method called printAnimal that will override the method with the same name within the class Animal. This method will also have no incoming parameters. It will simply print information about the current state (i.e. value) of each instance variable. For this print statement you must precede the string that you are going to print out with something like From Lion: to indicate that the printing is being conducted within the class Lion. Also, this method must invoke the method printAnimal within the superclass/parent (i.e. Animal class). This method will not return anything. This class will have another method called getNumEyes that will have no incoming parameters but will return the value of the instance variable eyes. This class will have another method called setLegs that will accept one incoming parameter. This method will then set the value of the instance variable legs by calling its parents (i.e. Animal class) own method setLegs to do this task. This method will not return anything. This class will have another method called setEyes that will accept one incoming parameter. This method will then set the value of the instance variable eyes to the value of the incoming parameter. This method will not return anything.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Modern Database Management

Authors: Jeff Hoffer, Ramesh Venkataraman, Heikki Topi

12th edition

133544613, 978-0133544619

More Books

Students also viewed these Databases questions

Question

3. Develop a case study.

Answered: 1 week ago