Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Exercise 1 Create an abstract class called GeometricShape. A GeometricShape has

ID: 3907297 • Letter: E

Question

Exercise 1 Create an abstract class called GeometricShape. A GeometricShape has a color and may or may not be filled with that color. GeometricShape should contain a default constructor that creates a shape filled with the color white, as well as getters and setters for the two instance data and a toString method. Create two abstract methods: one for getting the area of a shape, and one for getting the perimeter of a shape. Exercise 2 Modify Geometric shape so that it implements the comparable interface. Then create a static method called max that accepts two GeometricShapes as parameters and returns the larger of the two objects. If the objects are the same size, return the first object passed as a parameter.

Explanation / Answer

Hi,

Exercise 1 solution :

public abstract class GeometryShape {

//private data members

private String color;

private int Shape;

//constructor

public GeometryShape() {

super();

this.color="white";

}

//getters and setters

public String getColor() {

return color;

}

public void setColor(String color) {

this.color = color;

}

public int Shape() {

return Shape;

}

public void setFilled(int Shape) {

this.Shape = Shape;

}

//toString method

@Override

public String toString() {

return "GeometryShape [color=" + color + ", Shape=" + Shape + "]";

}

abstract int getArea();

abstract int getPerimeter();

}

Excerise 2 Solution :

public abstract class GeometryShape implements Comparable<GeometryShape>{

//private data members

private String color;

private int Shape;

//constructor

public GeometryShape() {

super();

this.color="white";

}

//getters and setters

public String getColor() {

return color;

}

public void setColor(String color) {

this.color = color;

}

public int Shape() {

return Shape;

}

public void setFilled(int Shape) {

this.Shape = Shape;

}

//toString method

@Override

public String toString() {

return "GeometryShape [color=" + color + ", Shape=" + Shape + "]";

}

abstract int getArea();

abstract int getPerimeter();

public GeometryShape max(GeometryShape s1, GeometryShape s2){  

if(s1.Shape==s2.Shape)  

return s1;

else if(s1.Shape>s2.Shape)  

return s1;  

else  

return s2;  

}  

}

Happy Learning :)