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 area of the triangle.
* A method named getPerimeter() that returns the perimeter of this triangle.
* A method name toString() that returns a string description for the triangle.
The GeometricObject class can be found on page 375 of the textbook (it is named GeometricObject1 there, but change the name).
The formula for computing the area of a triangle can be found pn page 68 of the textbook.
Write a test program that creates a Triangle object with sides 1, 1.5, 1, color yellow, and filled true, and displays the area, perimeter, color, and whetherfilled or not.
class GeometricObject
{
private String color = "white";
private boolean filled;
public Geometricobject(String color, double weight)
{
this.color = color;
this.weight = weight;
}
//getColor()
public String getColor()
{
return color;
}
//setColor
public void setColor(String color)
{
this.color = color;
}
//getWeight
public double getWeight()
{
return weight;
}
//setWeight
public void setWeight(double weight)
{
this.weight = weight;
}
//for find area and perimeter
public abstract double findArea();
public abstract double findPerimeter();
}
}
//Triangle class extends Geometricobject
class Triangle extends Geometricobject
{
//variable declartion
double side1,side2,side3;
boolean filled;
//findArea()
public double findArea()
{
//varaible declartion
double area,s;
//calculatting s
s = ( side1 + side2 + side3 ) /2;
//calculatting area
area = Math.sqrt(s * (s-side1) * (s-side2) * (s-side3));
//return area
return area;
}//end findArea()
//Triangle
public Triangle(double s1,double s2,double s3)
{
side1=s1;
side2=s2;
side3=s3;
}
public void setFilled(boolean tri)
{
filled = tri;
}
public boolean getFilled()
{
return filled;
}
public double findPerimeter()
{
double perimeter;
//calculatting perimeter
perimeter = (side1 + side2 + side3);
return perimeter;
}
public String toString()
{
return "Triangle: side1 = " + side1 + " side2 = " + side2 + "side3 = " + side3;
}
public static void main(String args[])
{
Triangle tri = new Triangle(1, 1.5, 1);
tri.setColor("yellow");
tri.setFilled(true);
System.out.println("The area is " + tri.findArea());
System.out.println("The perimeter is " + tri.findPerimeter());
System.out.println(" color is " + tri.getColor());
System.out.println("filled " + tri.getFilled());
}
}
Introduction to Java:Design a class named Triangle that extends GeometricObject.
(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 -...
Write a class named Octagon (Octagon.java) that extends the following abstract GeometricObject class and implements the Comparable and Cloneable interfaces. //GeometricObject.java: The abstract GeometricObject class public abstract class GeometricObject { private String color = "white"; private boolean filled; private java.util.Date dateCreated; /** Construct a default geometric object */ protected GeometricObject() { dateCreated = new java.util.Date(); } /** Construct a geometric object with color and filled value */ protected GeometricObject(String color, boolean filled) { dateCreated = new java.util.Date(); this.color = color;...
Why is my program returning 0 for the area of a triangle? public class GeometricObjects { private String color = " white "; private boolean filled; private java.util.Date dateCreated; public GeometricObjects() { dateCreated = new java.util.Date(); } public GeometricObjects(String color, boolean filled) { dateCreated = new java.util.Date(); this.color = color; this.filled = filled; } public String getColor() { return color; } public void setColor(String color)...
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...
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...
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 programming 1. (Triangle class) Design a new Triangle class that extends the abstract GeometricObject class. Draw the UML diagram for the classes Triangle and GeometricObject and then implement the Triangle class. Write a test program that prompts the user to enter three sides of the triangle, a color, and a Boolean value to indicate whether the triangle is filled. The program should create a Triangle object with these sides and set the color and filled properties using the input....