Question: ( The Colorable interface ) Design an interface named Colorable with a void method named howToColor() . Every class of a colorable object must imple-
(The Colorable interface) Design an interface named Colorable with a void method named howToColor(). Every class of a colorable object must imple- ment the Colorable interface. Design a class named Square that extends GeometricObject and implements Colorable. Implement howToColor to display the message Color all four sides.
Draw a UML diagram that involves Colorable, Square, and GeometricObject. Write a test program that creates an array of five GeometricObjects. For each object in the array, display its area and invoke its howToColor method if it is colorable.
I have written this so far but it keeps breaking:
public interface Colorable { public void howToColor(); } class GeometricObject { public GeometricObject() { } } class Square extends GeometricObject implements Comparable { public Square() { } public void howToColor() { System.out.println("Colorable all four sides"); } } public class ColorableTest { public static void main(String[] args) { GeometricObject[] obj = new GeometricObject[5]; obj[0] = new GeometricObject(); obj[1] = new Square(); obj[2] = new Square(); obj[3] = new GeometricObject(); obj[4] = new Square(); for (int i = 0; i < obj.length; i++) { GeometricObject object = obj[1]; System.out.print("Object[" + i + "] "); if (object instanceof Colorable) { Colorable colorable = (Colorable) object ; colorable.howToColor(); } else { System.out.println(" Not colorable"); } } } } Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
