Geometricobject is an abstract class with two abstract


Java - Polymorphism'
Instructions:
This compressed folder should contain the following files:
1. Colorable.java
2. GeometricObject.java
3. Square.java
4. Circle.java
5. TestPolymorphism.java
6. A readme.txt containing any instructions you want to provide to your instructor
• Make sure your java files compile without any compiler errors. You will not receive any credit for programs with compiler errors.

The Colorable Interface
Step 1: Design an interface named Colorable with a void method named howToColor().
Every class of a colorable object must implement the Colorable interface.
Step 2: GeometricObject is an abstract class with two abstract methods getArea and getPerimeter. Implementation of GeometricObject is provided below. To this impl- mentation, add the abstract methods getArea and getPerimeter.
Step 3: Design a class named Square as follows:
• It extends GeometricObject
• It implements Colorable
• Has a 1-arg constructor that takes side as an argument
• Has one new data field that is a double side
• Overrides the getArea and getPerimeter method
• Implements howToColor to display a message on how to color the square (For exam-
ple, prints the string "Color all four sides"). Step 4: Create a Circle class as follows:
?
• Extend GeometricObject
• Has a 1-arg constructor that takes radius as an argument • Has a new data field double radius
• Overrides the getArea and getPerimeter method
• Does not implement Colorable Interface.
Step 5: Create TestPolymorphism.java that tests the interface and classes that you just created. It should do the following:
1. Creates an array of five GeometricObjects. Add both Square and Circle objects to the array.
2. For each object in the array, invoke its howToColor method if it is colorable.
3. For each object invoke the getArea and getPerimeter methods.
GeometricObject class is provided below:
// GeometricObject.java: The abstract GeometricObject class
public abstract class GeometricObject {
private String color = "white";
private boolean filled;
/**Default constructor*/
protected GeometricObject() {
}
/**Construct a geometric object*/
protected GeometricObject(String color, boolean filled) {
this.color = color;
this.filled = filled;
}
/**Get method for color*/
public String getColor() {
return color;
}
/**Set method for color*/
public void setColor(String color) {
this.color = color;
}
2
?
/**Get method for filled. Since filled is boolean,
so, the get method name is isFilled*/
public boolean isFilled() {
return filled;
}
/**Set method for filled*/
public void setFilled(boolean filled) {
this.filled = filled;
}

Request for Solution File

Ask an Expert for Answer!!
JAVA Programming: Geometricobject is an abstract class with two abstract
Reference No:- TGS087124

Expected delivery within 24 Hours