Question: package geometricobjects; import java.util. * ; class GeometricObjects { private String color; private boolean filled; public GeometricObjects ( ) { this.color = white; this.filled =
package geometricobjects; import java.util.; class GeometricObjects private String color; private boolean filled; public GeometricObjects this.color "white"; this.filled false; Construct Geometric Object with specified color and filled value public GeometricObjectsString color, boolean filled this.color color; this.filled filled; Return Color public String getColor return color; Return filled. Since filled is boolean we name it isFilled public boolean isFilled return filled; Set new color public void setColorString color this.color color; Set new filled public void setFilledboolean filled this.filled filled; toString method that returns the string representation of object. This method also fetches the values of color and filled ie works like a getter too @Override public String toString return "Object color is: this.getColor object filled is: this.isFilled; class Triangle extends GeometricObjects private double side side side; public Triangledouble side double side double side String color, boolean filled supercolor filled; this.side side; this.side side; this.side side; public Triangle super; this.side; this.side; this.side; Accessors public double getA return this.side; public double getB return this.side; public double getC return this.side; public double getPerimeter return side side side; public double getArea double s side side side; double area s s sides sides side; return Math.sqrtarea; @Override public String toString return "Triangle: side side side side side side; class TestTriangle public static void mainString args try Scanner sc new ScannerSystemin System.out.printEnter color of Triangle: ; String color scnext; System.out.printIs Triangle filled? truefalse: ; boolean filled scnextBoolean; System.out.printEnter side: ; double side scnextDouble; System.out.printEnter side: ; double side scnextDouble; System.out.printEnter side: ; double side scnextDouble; Create object Triangle t new Triangleside side side color, filled; System.out.printlnt; System.out.printlnIs Triangle filled? tisFilled; System.out.printlnColor of the Triangle: tgetColor; System.out.printlnArea of the Triangle: tgetArea; System.out.printlnPerimeter of the Triangle: tgetPerimeter;
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
