Starting from:

$24.99

CSC1302 Lab 11- Java Inheritance Solution


Purpose:
A class in Java can extend another class to become a subclass. When class B extends class A, B becomes subclass (child) and A becomes superclass (parent). The subclass can reuse all the features of the parent class. An interface defines a set of specifications that other classes must implement. Implementing an interface allows a class to become more formal about the behavior it promises to provide.

In this assignment, we will practice how to extend classes and create corresponding objects. We will also practice using the interface. The meaning of implementing an interface is not very different than extending a class but it comes with an additional caveat. When a class implements an interface, it has to provide an implementation of all methods declared inside interface.
Criteria:
1. Upload all of the .java and the .class files to the CSc1302 dropbox on http:// icollege.gsu.edu.
3. Please comment the important lines in the .java file as shown in the template. The important lines including but not limited to i) variables, ii) for-loop, iii) while-loop, iv) if-else statement, iv) methods. Please use your own words to describe what is your purpose to write this line. A .java file without comment will be graded under a 40% penalty.
4. Make sure that both the .java and .class files are named and uploaded to icollege correctly. If any special package is used in the program, be sure to upload the package too. Should you use any other subdirectory (whatsoever) your program would not be graded, and you will receive a 0 (zero).
5. No copying allowed. If it is found that students copy from each other, all of these programs will get 0.
Task:
1. Write a superclass called Animal with the following:
i. Private Fields: vegetarian(boolean), eats(String), NumLegs(int)
ii. Constructor: Animal (Boolean veg, String food, int legs)
iii. Methods: IsVegetarian : return vegetarian
Please write the correct constructor and corresponding setter and getter.
2. Write a subclass Cat, extends Animal:
i. Private Fields: color (string)
ii. Methods: getColor: return color
Please write the correct constructor and corresponding setter and getter.
3. Write a class called Lab11, with the main method. In the main method, create an object of class Cat, which includes four attributes: not vegetarian, eats meats, four legs and white color. Print out these four attributes for this cat.
System.out.println("Cat is Vegetarian?" + _____);
System.out.println("Cat eats " + _____);
System.out.println("Cat has " + _____ + " legs.");
System.out.println("Cat color is " + _____);

More products