Reference no: EM132096038
PLEASE!! Any Help would be great
1. Design an interface named Colorable with a void method named howToColor().
2. Design a class named Geometry that implements the Comparable interface. The class contains:
a. Two integer data fields named GeometricId and numOfSides. GeometricId, initialized to 1, specifies the unique identifier whose value is automatically assigned to every instance of Geometric class by its constructors; numOfSides specifies the number of sides of an instance of a Geometric class;
b. A string field named color that stores the color of the Geometric object;
c. A no-arg constructor that creates a Geometric object with a unique GeometricId;
d. A constructor that creates a Geometric object with specified color and number of sides. The constructor should also assign a unique identifier to GeometricId field;
e. Implements compareTo method based on the number of sides. (Note: you are allowed to add extra fields or methods if necessary)
3. Design a class named Square that extends Geometry and implements the Colorable interface. The class contains: a.
A constructor that creates a Square object with the specified color and sets the numOfSides field to 4.
b. Print the number of sides and color in howToColor() method.
c. Override toString() method to display all the data fields, including the superclass's field) of the Square
4. Design a class named Triangle that extends Geometry and implements the Colorable interface. The class contains: a.
A constructor that creates a Traingle object with the specified color and sets the numOfSides field to
b. Print the number of sides and color in howToColor() method.
c. Override toString() method to display all the data fields, including the superclass's field) of the Triangle.
5. Design a class named Test that contains the following methods:
a. A static void Generic method displayGeometricObject that reads a generic array, named inputArray, of objects and does the following for every object in the array:
a. If the object at a particular index in inputArray is Square, the method displays the square properties defined in toString method and also calls the howToColor() method.
b. If the object at a particular index in inputArray is Triangle, the method displays the Triangle properties defined in toString method and also calls the howToColor() method.
b. Copy the following main method:
public static void main(String[] args) {
Geometry[] inputArray = new Geometry[3];
inputArray[0] = new Square("red");
inputArray[1] = new Triangle("yellow");
inputArray[2] = new Square("green");
displayGeometricObject(inputArray);
java.util.Arrays.sort(inputArray);
System.out.println("Geometric objects in the increasing order of their number of sides");
displayGeometricObject(inputArray); }
Sample Output: Square: ID: 1 Number of sides: 4 Color: red Print all the 4 sides with color: red Triangle:
ID: 2 Number of sides: 3 Color: yellow Print all the 3 sides of Triangle with color: yellow Square:
ID: 3 Number of sides: 4 Color: green Print all the 4 sides with color: green Geometric objects in the increasing order of their number of sides Triangle:
ID: 2 Number of sides: 3 Color: yellow Print all the 3 sides of Triangle with color: yellow Square:
ID: 1 Number of sides: 4 Color: red Print all the 4 sides with color: red Square:
ID: 3 Number of sides: 4 Color: green Print all the 4 sides with color: green