Triangle
Triangle
import java.util.*;
/**
* Write a description of class Polygon here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Triangle
{
Point v1 , v2 , v3;//These instance variables store the point value for each vertice
of a triangle
Line s1 , s2 , s3;//These variables store each side of the triangle
//Default constructor
public Triangle()
{
v1 = new Point();
v1.x = 0;
v1.y = -4;
v2 = new Point();
v2.x = 0;
v2.y = 4;
v3 = new Point();
v3.x = 4;
v3.y = 0;
}
//Parameterised Constructor
public Triangle(Point v1 , Point v2 , Point v3)
{
this.v1 = v1;
this.v2 = v2;
this.v3 = v3;
s1 = new Line();
s1.p1 = v1;
s1.p2 = v2;
s2 = new Line();
s2.p1 = v2;
s2.p2 = v3;
s3 = new Line();
s3.p1 = v3;
s3.p2 = v1;
}
//Parameterised Constructor
public Triangle(Line s1 , Line s2 , Line s3)
{
this.s1 = s1;
this.s2 = s2;
this.s3 = s3;
}
//This Function allows user to edit the coordinates
void editVertices()
{
Scanner sc = new Scanner(System.in);
int option ;
double x , y;
v1.printCoordinates();
System.out.println();
System.out.println("Enter 1. to edit vertice 1 or Enter 0.");
option = sc.nextInt();
File: Untitled Document 1 Page 2 of 3
if(option == 1)
{
v1.readCoordinates();
System.out.println();
}
v2.printCoordinates();
System.out.println();
System.out.println("Enter 1. to edit vertice 2 or Enter 0.");
option = sc.nextInt();
if(option == 1)
{
v2.readCoordinates();
System.out.println();
}
v3.printCoordinates();
System.out.println();
System.out.println("Enter 1. to edit vertice 3 or Enter 0.");
option = sc.nextInt();
if(option == 1)
{
v3.readCoordinates();
System.out.println();
}
/**
* Output:
*
* The coordinates of the points are :0.0,-4.0
Enter 1. to edit vertice 1 or Enter 0.
0
The coordinates of the points are :0.0,4.0
Enter 1. to edit vertice 2 or Enter 0.
0
The coordinates of the points are :4.0,0.0
Enter 1. to edit vertice 3 or Enter 0.
0
*/
}
boolean isTriangle()
{
double d1 = s1.getLength();
double d2 = s2.getLength();
double d3 = s3.getLength();
return d1+d2 > d3 ;
}