Question: JAVA PROGRAMMING: Complete the following classes in Java: Class Animal : Complete this class Class Dog : Write this class Class Cat : write this
JAVA PROGRAMMING:
Complete the following classes in Java:
- Class Animal : Complete this class
- Class Dog : Write this class
- Class Cat : write this class The files are provided and you need to follow the given instructions. The tester class (TestAnimals) is provided and you are not allowed to change it.
//Complete these classes:
import java.util.Scanner ; class TestAnimals { public static Scanner KB = new Scanner(System.in); public static void main(String[] args) { Animal myAnimal = new Animal(); // Create a Animal object Cat myCat = new Cat("Med","Floffy",1111); // Create a Cat object Dog myDog = new Dog(); // Create a Dog object myAnimal.sound(); myCat.sound(); myDog.sound(); String temp = KB.nextLine(); myDog.setName(tepm); myDog.setId(myCat.getId() + 1); System.out.println(myCat + " " + myDog); } }
public class Animal { /* Define the following for Animal class - Instance variables name(protected) and ID (private) - setters and getters - toString (Name and id to be returned and seperated by tabs) - 2 constructors ( default, parenthesized (name and id))
/* Type your code here. */ public void sound() { System.out.print("The animal sound is: "); }
}
/* Define the following for Dog class that inherits from Animal class - Instance variables breed (private) - setters and getters - toString (breed is added to Name and id to be returned and seperated by tabs) - 2 constructors ( default, parenthesized (breed,name and id)) - Override sound method to print the parent class sound and add woof woof to it */
/* Define the following for Cat class that inherits from Animal class - Instance variables size (private) - setters and getters - toString (size is added to Name and id to be returned and seperated by tabs) - 2 constructors ( default, parenthesized (size,name and id)) - Override sound method to print the parent class sound and add meow meow to it */
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
