Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Rectangle Class : public class Regtangle extends GeometryShape { private double length; private double width; public Regtangle (double length, double width, String color){ super(color); this.length

Rectangle Class : public class Regtangle extends GeometryShape { private double length; private double width; public Regtangle (double length, double width, String color){ super(color); this.length = length; this.width = width; } public void setLength (double le) { length = le; } public void setWidth (double we) { width = we ; } public double getLength (){ return length; } public double getWidth (){ return width; } public double area(){ return length*width; } public double perimeter(){ return 2*length+2*width; } public String toString(){ //String str; return super.toString() + "Length :" + length + " Width :" + width + " Color :" + color; } }

GeometryShape Class : public class GeometryShape { protected String color; public GeometryShape(String color){ this.color = color; } public void setColor(String c){ color = c; } public String getColor(){ return color; } public String toString(){ String str; str = "Color :" + color; return str; } }

Cuboid Class : public class Cuboid extends Regtangle { private double height; public Cuboid(double length, double width, double height, String color){ super(length, width, color); this.height = height; } public void setHeight (double h) { height = h; } public double getHeight(){ return height; } public double volume(){ return getLength()*getWidth()*height; } public String toString(){ //String str; //str = "Hieght :" + height; return super.toString() + "Height :" + height; } }

Main program : public class DemoProgram {

public static void main(String[] args) { Scanner input = new Scanner(System.in); double length, width, height; String color; System.out.println("Enter a length"); length = input.nextDouble(); System.out.println("Enter a width"); width = input.nextDouble(); System.out.println("Enter a height"); height = input.nextDouble(); System.out.println("Enter a color"); color = input.next(); //Regtangle regt = new Regtangle (); GeometryShape shape = new GeometryShape(color); Regtangle regt2 = new Regtangle (length, width, color); Cuboid cub = new Cuboid(height, length, width, color); //regt.setLength(length); //regt.setWidth(width); System.out.println(" Rectangle : " + regt2 + " Area is :" + regt2.area()); length = 12; cub.setLength(length); cub.setColor("Black"); System.out.println(" Cuboid : " + cub + " Volume is :" + cub.volume()); //System.out.println(shape); //System.out.println(" Volume : " + cub.volume()); //System.out.println("Length value is :" + regt2.getLength()); //System.out.println("Width value is : " + regt2.getWidth() + " Area: " + regt2.area() // + " Perimeter :" + regt2.perimeter()); } }

Please Draw a UML diagram for the above code

you are only required to draw the UML diagram for the scenario above.

Subject: OOP In JAVA.

Thank you

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

9. Make sure goals are internalized and accepted by the athlete.

Answered: 1 week ago

Question

Explain all drawbacks of application procedure.

Answered: 1 week ago