Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The inheritance program created in homework #3 was successful and used for dog animal shelter management. However, the dog shelter wants to add cats and

The inheritance program created in homework #3 was successful and used for dog animal shelter management. However, the dog shelter wants to add cats and requests a modification to the program. Cats still need a name but they do not need to be tracked by breed, as dogs do, instead the cats need to be tracked by type on whether they are inside or outside cats. The shelter has found that while cats and dogs have many characteristics, the main attribute for effective shelter management is to group them by breed for dogs and type (inside or outside) for cats. Retain the super class Animal that uses Name and the subclass Dog that uses breed, and add a new Cat subclass that uses type (inside or outside). Print everything out for the current dogs and some new cats as defined in the driver program TestInheritance (where main is located). So to reiterate, use the program previously developed in homework #3 and add the subclass Cat. Keep the current Dog subclass but instead of breed used by dog, use type (insider or outside) for the new cat subclass. You can use the dog subclass developed previously as a model to develop the new cat subclass. Use the Animal superclass, dog subclass, new cat subclass, and driver TestInheritance already provided in the template in this homework #4 which was previously used in homework #3. Note that the TestInheritance driver retains the current dogs but adds "Sammy" which is an outside cat and "Ralph" which is an inside cat. The instructor will not provide the solution to this particular Zylab Homework #4, so development of the new Cat subclass should be created using the previous homework #3 Dog subclass as a reference, internet sources, and help from your friends in class. There is no program input to type in when running the program. There is 1 point max for this homework.

//superclass Animal class Animal { private String name; public void setName (String n) { name = n; } public String getName() { return name; } }

//subclass Dog class Dog extends Animal { private String breed; public void setBreed(String br) { breed = br; } public String getBreed() { return breed; } } // add the new subclass Cat after this line using inheritance

//driver program, the new Cat modifications are already added public class TestInheritance { public static void main(String[] args) { Dog dg = new Dog(); Dog dg1 = new Dog(); Cat ct = new Cat(); Cat ct1 = new Cat(); dg.setName("Lassie"); dg.setBreed("collie"); dg1.setName("Benji"); dg1.setBreed("mixed"); ct.setName("Sammy"); ct.setType("outside"); ct1.setName("Ralph"); ct1.setType("inside"); System.out.println("Dog Name: " + dg.getName()); System.out.println("Dog Breed: " + dg.getBreed()); System.out.println("Dog Name: " + dg1.getName()); System.out.println("Dog Breed: " + dg1.getBreed()); System.out.println("Cat Name: " + ct.getName()); System.out.println("Cat Type: " + ct.getType()); System.out.println("Cat Name: " + ct1.getName()); System.out.println("Cat Type: " + ct1.getType()); } }

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

More Books

Students also viewed these Databases questions

Question

What do you mean by Dividend ?

Answered: 1 week ago

Question

What is database?

Answered: 1 week ago

Question

What are Mergers ?

Answered: 1 week ago