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 GeometricObjects(String 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 setColor(String color){ this.color = color; }/* Set new filled */ public void setFilled(boolean filled){ this.filled = filled; }/* toString method that returns the string representation of object. This method also fetches the values of color and filled--- i.e. 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 side1, side2, side3; public Triangle(double side1, double side2, double side3, String color, boolean filled){ super(color, filled); this.side1= side1; this.side2= side2; this.side3= side3; } public Triangle(){ super(); this.side1=1; this.side2=1; this.side3=1; }// Accessors public double getA(){ return this.side1; } public double getB(){ return this.side2; } public double getC(){ return this.side3; } public double getPerimeter(){ return side1+ side2+ side3; } public double getArea(){ double s =(side1+ side2+ side3)/2; double area = s *(s - side1)*(s - side2)*(s - side3); return Math.sqrt(area); } @Override public String toString(){ return "Triangle: side1="+ side1+" side2="+ side2+" side3="+ side3; }} class TestTriangle { public static void main(String[] args){ try (Scanner sc = new Scanner(System.in)){ System.out.print("Enter color of Triangle: "); String color = sc.next(); System.out.print("Is Triangle filled? (true/false): "); boolean filled = sc.nextBoolean(); System.out.print("Enter side1: "); double side1= sc.nextDouble(); System.out.print("Enter side2: "); double side2= sc.nextDouble(); System.out.print("Enter side3: "); double side3= sc.nextDouble(); // Create object Triangle t1= new Triangle(side1, side2, side3, color, filled); System.out.println(t1); System.out.println("Is Triangle filled? "+ t1.isFilled()); System.out.println("Color of the Triangle: "+ t1.getColor()); System.out.println("Area of the Triangle: "+ t1.getArea()); System.out.println("Perimeter of the Triangle: "+ t1.getPerimeter()); }}}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!