Design a general class GeometricObject can be used to model all geometric objects. This class contains the properties color and filled and their appropriate get and set methods. Assume that this class also contains toString() methods. The toString() method returns a string representation of the object.
Define the Triangle, Circle, and Rectangle classes that extend the GeometricObject class.
return "Triangle: side1 = " + side1 + " side2 = " + side2 + " side3 = " + side3;
Design a Test class which creates objects of Triangle, Circle and Rectangle and invokes the methods on these objects. The toString() method is inherited from the GeometricObject class and is invoked from a Triangle object, Circle object and a Rectangle object.
Please take care at the input data. The input data have to be eligible (numeric values) and you have to verify the existence of objects ( for example : the width and height of rectangle have to be positive numbers).
If the input data is not correct , you have to ask the user to enter again the data
1. all sides have to be positive
2. for triangle you need to verify the Triangle ABC Inequality Theorem yields three inequalities:
AB + BC > CA
BC + CA > AB
CA + AB > BC
public class GeometricObject {
//properties of class
String color,filled;
public String getColor(){
return color;
}
public void setColor(String color) {
this.color = color;
}
public String getFilled() {
return filled;
}
//getter methods
public void setFilled(String filled) {
this.filled = filled;
}
//to string method
public String toString() {
return "Color="+color+",Filled="+filled;
}
}
-------------------------------
public class Triangle extends GeometricObject{
double side1,side2,side3;
public Triangle(double side1, double side2, double side3,String
clr,String fill) {
this.side1 = side1;
this.side2 = side2;
this.side3 = side3;
super.color=clr;
super.filled=fill;
}
public String toString(){
return
"Triangle:"+super.toString()+",Side1="+side1+",Side2="+side2+",Side3="+side3;
}
}
---------------------------------------------
public class Circle extends GeometricObject{
//property
double radius;
//constructor
public Circle(double radius,String clr,String fill) {
this.radius = radius;
super.color=clr;
super.filled=fill;
}
//getter & setter methods
public double getRadius() {
return radius;
}
public void setRadius(double radius) {
this.radius = radius;
}
//methods for calculating area, perimeter and diameter of
circle
double getArea(){
return 22*radius*radius/7;
}
double getPerimeter(){
return 2*22*radius/7;
}
double getDiameter(){
return 2*radius;
}
//method to show the object content in string form
public String toString(){
return
"Circle:"+super.toString()+",Area="+getArea()+",Perimeter="+getPerimeter()+",Diameter="+getDiameter();
}
}
-----------------------------------------------------
public class Rectangle extends GeometricObject{
//properties of object
double width,height;
//constructor
public Rectangle(double width, double height,String clr,String
fill) {
this.width = width;
this.height = height;
super.color=clr;
super.filled=fill;
}
//getter and setter methods
public double getWidth() {
return width;
}
public void setWidth(double width) {
this.width = width;
}
public double getHeight() {
return height;
}
public void setHeight(double height) {
this.height = height;
}
//methods to calculate area and perimeter
double getArea(){
return width*height;
}
double getPerimeter(){
return 2*(width+height);
}
//method to show the object content in string form
public String toString(){
return
"Rectangle:"+super.toString()+",Area="+getArea()+",Perimeter="+getPerimeter();
}
}
------------------------------------------------------------
//importing required classes
import java.util.Scanner;
public class GeometricObjectTest {
//main method definition
public static void main(String[] args) {
//creating stream to receive user input
Scanner input=new Scanner(System.in);
//variable
int choice;
System.out.print("1.Triangle 2.Circle 3.Rectangle Enter the shape
choice=");
choice=input.nextInt();
//operating on the selected shape
switch(choice){
case 1:{
int side1,side2,side3;
String clr,fill;
do{
System.out.print("Enter the first side of triangle: ");
side1=input.nextInt();
System.out.print("Enter the second side of triangle: ");
side2=input.nextInt();
System.out.print("Enter the third side of triangle: ");
side3=input.nextInt();
System.out.print("Enter the color of triangle: ");
clr=input.next();
System.out.print("Is triangle filled?(true/false): ");
fill=input.next();
}while(side1<0||side2 < 0||side3<0);
Triangle tri=new Triangle(side1,side2,side3,clr,fill);
System.out.println(tri.toString());
break;
}
case 2:{
int r;
String clr,fill;
do{
System.out.print("Enter the radius of circlr: ");
r=input.nextInt();
System.out.print("Enter the color of circlr: ");
clr=input.next();
System.out.print("Is circle filled?(true/false): ");
fill=input.next();
}while(r<0);
Circle cir=new Circle(r, clr, fill);
System.out.println(cir.toString());
break;
}
case 3:{
int w,h;
String clr,fill;
do{
System.out.print("Enter the width of rectangle: ");
w=input.nextInt();
System.out.print("Enter the height of rectangle: ");
h=input.nextInt();
System.out.print("Enter the color of rectangle: ");
clr=input.next();
System.out.print("Is rectangle filled?(true/false): ");
fill=input.next();
}while(w<0||h<0);
Rectangle rec=new Rectangle(w, h, clr, fill);
System.out.println(rec.toString());
break;
}
}
}
}
-------------------------------------------------
Output:

Design a general class GeometricObject can be used to model all geometric objects. This class contains...
Please include comments in the program .The program must be able to be compiled.Design a class named Triangle that extends GeometricObject. This class contains:* Three double data fields named side1, side2, and side3 with default values 1.0 to denote the three sides of a triangle.* A no-arg constructor that creates a default triangle.* A constructor that creates a triangle with the specified side1, side2, and side3.* The accessor methods for all three data fields.* A method named getArea() that returns...
(The Triangle class) Design a class named Triangle that extends the GeometricObject class. The Triangle class contains: - Three float data fields named side1, side2, and side3 to denote the three sides of the triangle. - A constructor that creates a triangle with the specified side1, side2, and side3 with default values 1.0. - The accessor methods for all three data fields. - A method named getArea() that returns the area of this triangle. - A method named getPerimeter() that...
Design a class named Triangle that extends GeometricObject class. The class contains: Three double data fields named side1, side2, and side3 with default values 1.0 to denote three sides of the triangle. A no-arg constructor that creates a default triangle with color = "blue", filled = true. A constructor that creates a triangle with the specified side1, side2, side3 and color = "blue", filled = true. The accessor functions for all three data fields, named getSide1(), getSide2(), getSide3(). A function...
Must be in Python 3.6 (please have a screen shot on the
code)
ex 2.14 :
# Enter three points for a triangle
x1, y1, x2, y2, x3, y3 = eval(input("Enter three points for a
triangle: "))
# Compute the length of the three sides
side1 = ((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2)) **
0.5
side2 = ((x1 - x3) * (x1 - x3) + (y1 - y3) * (y1 -...
Objective Extend the class GeometicShapes to include a Triangle class.. Background Reading ZyBooks Chapter 10 Task Create the following fields and methods for a Triangle class that extends the provided GeometricShapes class public class GeometricShapes { private String color = "red"; private boolean filled; private java.util.Date dateCreated; public GeometricShapes() { dateCreated = new java.util.Date(); } public GeometricShapes(String color, boolean filled) { dateCreated = new java.util.Date(); this.color = color; this.filled = filled; } public void setColor (String color)...
Python only please, thanks in advance.
Type up the GeometricObject class (code given on the back of the paper). Name this file GeometricObjectClass and store it in the folder you made (xxlab14) 1. Design a class named Rectangle as a subclass of the GeometricObject class. Name the file RectangleClass and place it in the folder. 2. The Rectangle class contains Two float data fields named length and width A constructor that creates a rectangle with the specified fields with default...
Following the example of the Circle class in Section 8.2, design a class named Rectangle to represent a rectangle. The class contains: ■ 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...
(The Rectangle class) Following the example of the Circle class in Section 9.2, design a class named Rectangle to represent a rectangle. The class contains: ■ 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()...
Python only please, thanks in advance.
Type up the GeometricObject class (code given on the back of the paper). Name this file GeometricObjectClass and store it in the folder you made (xxlab14) 1. Design a class named Rectangle as a subclass of the GeometricObject class. Name the file RectangleClass and place it in the folder. 2. The Rectangle class contains Two float data fields named length and width A constructor that creates a rectangle with the specified fields with default...
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...