Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Within DrJava, you are to create four classes which are described below: Under no circumstances are you allowed to use the keyword this in any

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

image text in transcribed

Within DrJava, you are to create four classes which are described below: Under no circumstances are you allowed to use the keyword this in any part of your program. Any usage of the keyword this (even if it is used only one time) will be an automatic deduction of 10 points off your grade. 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. Make sure that you have mutator (set) methods and accessor (get) methods for each of the instance variables and that each of these methods uses the keyword final. These methods are to be called from the constructors to set up the initialization of the instance variables. 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. Use the accessor methods that you have created above in this method. 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. 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 (.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. Use the accessor methods that you have created in the Animal class. 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 setSpider Legs that will accept one incoming parameter. This method will then set the value of the instance variable legs by calling its parent's (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 (.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..value) of each instance variable. Use the accessor methods that you have created in the Animal class. 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 setLionLegs that will accept one incoming parameter. This method will then set the value of the instance variable legs by calling its parent's (i.e. Animal class) own method setLegs to do this task. This method will not return anything. AnimalTester class - this class will contain your main method. You will instantiate two Spider objects (spidyl and spidy2, respectively). spidyl will not have any arguments to the constructor. spidy2 will have the following values sent to the constructor: 8, 8, "insects", "very quiet". These values represent the number of legs, the number of eyes, what it eats, and the sound that it makes. You also need to instantiate a Lion object (lion). lion will have the following values sent to the constructor: 2, 1, "meat", "roar". These values represent same thing mentioned above. You are now to do the following sequence of statements: Print out the message "Going to print out info about spidy1" For spidyl invoke the method printAnimal Print out the message "Going to print out info about spidy2" For spidy2 invoke the method printAnimal Print out a message on how many eyes spidy1 has Print out a message on how many eyes spidy2 has For spidyl set its legs to the number 7 Print out the message "Going to print out info about spidy1" For spidyl invoke the method printAnimal Print out the message "Going to print out info about lion" For lion invoke the method printAnimal For lion set its legs to the number 4 Print out the message "Going to print out info about lion" For lion invoke the method printAnimal For lion set its eyes to the number 2 Print out the message "Going to print out info about lion" For lion invoke the method printAnimal Print out the message "This program was written by Dr. Castaneda" Print out the message "End of program." Note: In the above print statement make sure that you replace my name with your name. At the top of your program within the class AnimalTester make sure that you have the following header filled in: // - // Programmer: // Course: IS 2043 Section ### // Semester: // Assignment #: // Due Date: Expected Output: Going to print out info about spidy1 From Spider: legs O, eyes 0, eat nothing, says "nothing" From Animal: This animal has Olegs, O eyes, eats nothing, sounds "nothing" Going to print out info about spidy2 From Spider: legs 8, eyes 8, eat insects, says "very quiet" From Animal: This animal has 8 legs, 8 eyes, eats insects, sounds "very quiet" spidy1 has 0 eyes! But spidy2 has 8 eyes! Going to print out info about spidy1 From Spider: legs 7, eyes 0, eat nothing, says "nothing" From Animal: This animal has 7 legs, 0 eyes, eats nothing, sounds "nothing" Going to print out info about lion From Lion: legs 2, eyes 1, eat meat, sounds "roar" From Animal: This animal has 2 legs, 1 eyes, eats meat, sounds "roar" Going to print out info about lion From Lion: legs 4, eyes 1, eat meat, sounds "roar" From Animal: This animal has 4 legs, 1 eyes, eats meat, sounds "roar" Going to print out info about lion From Lion: legs 4, eyes 2, eat meat, sounds "roar" From Animal: This animal has 4 legs, 2 eyes, eats meat, sounds "roar

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

User Defined Tensor Data Analysis

Authors: Bin Dong ,Kesheng Wu ,Suren Byna

1st Edition

3030707490, 978-3030707491

Students also viewed these Databases questions

Question

What is "adequacy of consideration"?

Answered: 1 week ago

Question

Understand the use of visualizations as a tool in tax analytics.

Answered: 1 week ago