Question

I Need UML Design for the following Java code: Colorable interface: public interface Colorable { //a...

I Need UML Design for the following Java code:

Colorable interface:

public interface Colorable {

//a void method named howToColor().
void howToColor();
}

GeometricObject class:

public class GeometricObject {

}

Sqaure class:

public class Square extends GeometricObject implements Colorable{

//side variable of Square
double side;
  
//Implementing howToColor()
@Override
public void howToColor() {
System.out.println("Color all four sides.");
}
  
//setter and getter methods for Square
public void setSide(double side) {
this.side = side;
}
  
public double getSide() {
return this.side;
}
  
//calculating area of the Square
public void area() {
System.out.println("Square area: "+getSide() * getSide());
}
}


Rectangle class:

public class Rectangle extends GeometricObject implements Colorable{

//variables of Rectangle
double height;
double width;
  
  
@Override
public void howToColor() {
System.out.println("Color all four sides.");
}


//getter and setter methods for height and width
public double getHeight() {
return height;
}


public void setHeight(double height) {
this.height = height;
}


public double getWidth() {
return width;
}


public void setWidth(double width) {
this.width = width;
}

//calculating area of the Rectangle
public void area() {
System.out.println("Rectangle area: "+this.getHeight()* this.getWidth());
}
}

Circle class:

public class Circle extends GeometricObject implements Colorable {

//PIE value as constant
public static final double PIE = 3.14;
  
//radius variable of Circle
double radius;
  
@Override
public void howToColor() {
System.out.println("Color all around the circle.");
}

//setter and getter methods for Circle
public double getRadius() {
return radius;
}

public void setRadius(double radius) {
this.radius = radius;
}
  
//calculating area of the Circle
public void area() {
System.out.println("Circle area: "+PIE * this.getRadius() * this.getRadius());
}
}

Test class:

public class Test {

public static void main(String[] args) {
//creating an array of five GeometricObjects
GeometricObject[] geometricObjects = new GeometricObject[5];
  
//instance of Square class
Square square = new Square();
square.setSide(12.5);
  
Square square1 = new Square();
square1.setSide(8);
  
//instance of Circle class
Circle circle = new Circle();
circle.setRadius(9.6);
  
//instance of Rectangle class
Rectangle rectangle = new Rectangle();
rectangle.setHeight(10);
rectangle.setWidth(12);
  
Rectangle rectangle1 = new Rectangle();
rectangle1.setHeight(5.8);
rectangle1.setWidth(3.6);
  
//storing all the objects into array of GeometricObject
geometricObjects[0] = square;
geometricObjects[1] = square1;
geometricObjects[2] = circle;
geometricObjects[3] = rectangle;
geometricObjects[4] = rectangle1;
  
  
for(GeometricObject geometricObject: geometricObjects) {
//condition to check instance of each type in the geometricObjects array
if(geometricObject instanceof Circle) {
((Circle) geometricObject).area();
((Circle) geometricObject).howToColor();
System.out.print("\n");
}
else if(geometricObject instanceof Rectangle) {
((Rectangle) geometricObject).area();
((Rectangle) geometricObject).howToColor();
System.out.print("\n");
}
else if(geometricObject instanceof Square) {
((Square) geometricObject).area();
((Square) geometricObject).howToColor();
System.out.print("\n");
}
}
}

}

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Please find the UML below<<Abstract Class >> GeometricObject <<Class >> Circle <<extend>> GeometricObject() + area(): void -radius: double + Circle(ra

Please let me know if you have any doubt or modify the answer, Thanks :)

Add a comment
Know the answer?
Add Answer to:
I Need UML Design for the following Java code: Colorable interface: public interface Colorable { //a...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Receiveing this error message when running the Experts code below please fix ----jGRASP exec: javac -g...

    Receiveing this error message when running the Experts code below please fix ----jGRASP exec: javac -g GeometricObject.java GeometricObject.java:92: error: class, interface, or enum expected import java.util.Comparator; ^ 1 error ----jGRASP wedge2: exit code for process is 1. ----jGRASP: operation complete. 20.21 Please code using Java IDE. Please DO NOT use Toolkit. You can use a class for GeometricObject. MY IDE does not have access to import ToolKit.Circle;import. ToolKit.GeometricObject;.import ToolKit.Rectangle. Can you code this without using the ToolKit? Please show an...

  • Please, modify the code below to use the Switch Statements in Java instead of “if” statements...

    Please, modify the code below to use the Switch Statements in Java instead of “if” statements to make the decisions. import java.util.Scanner; public class Area { public static void main(String[] args) { Scanner in = new Scanner(System.in); System.out.print("Enter code(C for circle, R for rectangle, S for square): "); char code = in.next().charAt(0); if(code == 'C') { System.out.print("Enter radius: "); double radius = in.nextDouble(); System.out.println("Area of circle is " + (Math.PI * radius * radius)); } else if(code == 'R') {...

  • Define an interface named Shape with a single method named area that calculates the area of...

    Define an interface named Shape with a single method named area that calculates the area of the geometric shape:        public double area(); Next, define a class named Circle that implements Shape. The Circle class should have an instance variable for the radius, a constructor that sets the radius, an accessor and a mutator method for the radius, and an implementation of the area method. Define another class named Rectangle that implements Shape. The Rectangle class should have instance variables...

  • Why are obj1 and obj2 printing the same areas? I'm trying to learn about Comparable interface....

    Why are obj1 and obj2 printing the same areas? I'm trying to learn about Comparable interface. Couldn't figure it out. the compare to method should print 0, 1, or -1 import java.util.*; public class RectangleMain {    public static void main(String [] args) throws CloneNotSupportedException    {        /*ComparableRectangleAlsoCloneable obj1 = new ComparableRectangleAlsoCloneable(4, 5);        ComparableRectangleAlsoCloneable obj2 = (ComparableRectangleAlsoCloneable)obj1.clone();               System.out.println(obj1.toString());        System.out.println(obj1 == obj2); //false        System.out.println(obj2.toString());*/               Scanner...

  • JAVA design a class named Rectangle to represent a rectangle. The class contains: A method named getPerimeter() that returns the perimeter. Two double data fields named width and height that specify...

    JAVA design a class named Rectangle to represent a rectangle. The class contains: A method named getPerimeter() that returns the perimeter. Two double data fields named width and height that specify the width and height of the rectangle. The default values are 1 for both width and height. A no-arg constructor that creates a default rectangle. A constructor that creates a rectangle with the specified width and height. A method named getArea() that returns the area of this rectangle. design...

  • Create a Java Project in Eclipse with the following: Include the Rectangle class supplied below. Override...

    Create a Java Project in Eclipse with the following: Include the Rectangle class supplied below. Override the toString method for Rectangle. Override the equals method for Rectangle. Implement the comparable Interface for Rectangle (Compare by area) Rectangle class: public class Rectangle {       private double length;    private double width;       public Rectangle(double l, double w)    {        length = l;        width = w;    }       public double getLength()    {   ...

  • m The interface Measurable is defined as the following: /** An interface for methods that return...

    m The interface Measurable is defined as the following: /** An interface for methods that return the perimeter and area of an object. */ public interface Measurable { public double getPerimeter(); public double getArea(); } The class Rectangle implements the interface. The incomplete program is written as follows: 1 public class Rectangle 2 { private double width; private double height; public Rectangle(double w, double h) { width = w; height h; } { 3 4 5 6 7 8 9...

  • Consider the following declaration for a class that will be used to represent rectangles. public class...

    Consider the following declaration for a class that will be used to represent rectangles. public class Rectangle { private double height; private double width; public Rectangle() { height = 2.0; width = 1.0; } public Rectangle(double w, double h) { height = h; width = w; } public double getHeight() { return height; } public double getWidth() { return width; } public void setHeight(double h) { height = h; } public void setWidth(double w) { width = w; } //Other...

  • I am trying to write a Geometry.java program but Dr.Java is giving me errors and I...

    I am trying to write a Geometry.java program but Dr.Java is giving me errors and I dont know what I am doing wrong. import java.util.Scanner; /** This program demonstrates static methods */ public class Geometry { public static void main(String[] args) { int choice; // The user's choice double value = 0; // The method's return value char letter; // The user's Y or N decision double radius; // The radius of the circle double length; // The length of...

  • Show the output of running the class Test in the following code lines: interface A {...

    Show the output of running the class Test in the following code lines: interface A { void print (); } class C ( class B extends C implements A { public void print() { } } class Test { public static void main(String[] args) { B b = new B(); if (b instanceof A) System.out.println("b is an instance of A"); w class Test { public static void main(String[] args) { B b = new B(); if (b instanceof A) System.out.println("b...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT