Using Java DOWN BELOW IS THE CODE ----------------------------------------------
ID: 3858990 • Letter: U
Question
Using Java
DOWN BELOW IS THE CODE
----------------------------------------------------------------------------------------------------------
IV. Problem 3: 13.7 (revised): he Colorable interface) Design an interface named (The Colorable interface) Design an interface named Colorable with a void method named how ToColor (). Every class of a colorable object must implement the Colorable interface. Design a class tand implement Implement how ToColor to display the message "Color all four sides". Write a test program that creates two Squares with 5 and 5.5 as the sides. For each square, display its area and invoke its how ToColor methodExplanation / Answer
public class exam4p3Exercise13_07{
public static void main(String[] args) {
GeometricObject object1 = new Square(5);
GeometricObject object2 = new Square(5.5);
System.out.println("object1 Area is " + object1.getArea());
((Colorable)object1).howToColor();
//Some more instructions here!
System.out.println("object1 Area is " + object2.getArea());
((Colorable)object2).howToColor();
//Some more instructions here!
}
}
interface Colorable {
//You Complete this ....
void howToColor();
}
abstract class GeometricObject
{
public abstract double getArea();
public abstract double getPerimeter();
}
class Square extends GeometricObject implements Colorable//You complete this line
{
private double side;
public Square(double side) {
this.side = side;
}
@Override
public void howToColor() {
//You Complete this ....
System.out.println(" Color all four sides");
}
@Override
public double getArea() {
return side * side;
}
@Override
public double getPerimeter() {
return 4 * side;
}
}
Output:
object1 Area is 25.0
Color all four sides
object1 Area is 30.25
Color all four sides
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.