Patel Arth COSCLab2
Patel Arth COSCLab2
Triangle.java
// no-arg constructor
public Triangle()
{
this.side_1 = 0;
this.side_2 = 0;
this.side_3 = 0;
// getPerimeter method
public double getPerimeter()
{
return this.side_1 + this.side_2 + this.side_3;
}
// toString method
public String toString()
{
return "\nside1 = " + side_1
+ "\nside2 = " + side_2
+ "\nside3 = " + side_3
+ "\ncolor = " + this.getColor()
+ "\nfilled = " + this.isFilled();
}
}
GeometricObjectTest.java
import java.util.Scanner;
class Geometricobject
{
private String color;
private boolean filled;
}
public class GeometricobjectTest
{
input.nextLine();
System.out.print("Is triangle filled (true/false): ");
boolean filled = input.nextBoolean();
input.close();
Triangle triangle = new Triangle(sides[0], sides[1], sides[2]);
triangle.setColor(color);
triangle.setFilled(filled);
Output:
Methodology:
Firstly, the Triangle class extends geometricobject class and its inherits color and
filled attributes. Instance variable represents the sides of the tringle that is Side1,
Side2, and Side3 and apply getter and setter method for this sides. After that, I used
getperimeter method for the calculation of triangle perimeter. At last, I use tostring
method for triangle properties.
GeometricObjectTest this class is used for the test of Triangle class. Where I use
array to get the sides of triangle from user. First user enter three side of Triangle and
after that input color and value for triangle fill with the color or not. Last, it prints
Triangle Perimeter and its detail.
Conclusion:
Overall, we create two different java file that use one of class details in other and
print the amount or output that user want.