2. }
public double getCoodX2() {
return coodX2;
}
public void setCoodX2(double coodX2) {
this.coodX2 = coodX2;
}
public double getCoodY2() {
return coodY2;
}
public void setCoodY2(double coodY2) {
this.coodY2 = coodY2;
}
public double getCoodX3() {
return coodX3;
}
public void setCoodX3(double coodX3) {
this.coodX3 = coodX3;
}
public double getCoodY3() {
return coodY3;
}
public void setCoodY3(double coodY3) {
this.coodY3 = coodY3;
}
//This method will calculate the distance between the point
public double distance(double x1,double y1,double x2,double y2)
{
return Math.sqrt(Math.pow((x2-x1),2)+Math.pow((y2-y1),2));
}
//This method will calculate the angle between the two points
public double angleOfPoints(double x1,double y1,double x2,double y2)
{
double xDiff=x2-x1;
double yDiff=y2-y1;
double angle=Math.atan2(yDiff, xDiff)*(180/Math.PI);
3. return angle;
}
//This method will calculate the area of the triangle
public double getArea()
{
double lengthA=distance(getCoodX1(),getCoodY1(), getCoodX2(), getCoodY2());
double lengthB=distance(getCoodX2(),getCoodY2(), getCoodX3(), getCoodY3());
double lengthC=distance(getCoodX3(),getCoodY3(), getCoodX1(), getCoodY1());
double S=(lengthA+lengthB+lengthC)/2;
//Calculating the area
double area=Math.sqrt(S*(S-lengthA)*(S-lengthB)*(S-lengthC));
return area;
}
//This method will calculate the Perimeter of the triangle
public double getPerimeter()
{
double lengthA=distance(getCoodX1(),getCoodY1(), getCoodX2(), getCoodY2());
double lengthB=distance(getCoodX2(),getCoodY2(), getCoodX3(), getCoodY3());
double lengthC=distance(getCoodX3(),getCoodY3(), getCoodX1(), getCoodY1());
//Calculating the perimter
double S=(lengthA+lengthB+lengthC);
return S;
}
//Displaying the triangle is isosceles triangle or not
public void Isosceles()
{
double lengthA=distance(getCoodX1(),getCoodY1(), getCoodX2(), getCoodY2());
double lengthB=distance(getCoodX2(),getCoodY2(), getCoodX3(), getCoodY3());
double lengthC=distance(getCoodX3(),getCoodY3(), getCoodX1(), getCoodY1());
if((lengthA==lengthB) || (lengthB==lengthC) || (lengthC==lengthA) )
{
System.out.println(":: The Triangle is Isosceles ::");
}
else
4. System.out.println(":: The Triangle is Not Isosceles ::");
}
//Displaying the triangle is Equilateral triangle or not
public void Equilateral()
{
double lengthA=distance(getCoodX1(),getCoodY1(), getCoodX2(), getCoodY2());
double lengthB=distance(getCoodX2(),getCoodY2(), getCoodX3(), getCoodY3());
double lengthC=distance(getCoodX3(),getCoodY3(), getCoodX1(), getCoodY1());
if((lengthA==lengthB) && (lengthB==lengthC) && (lengthC==lengthA) )
{
System.out.println(":: The Triangle is Equilateral ::");
}
else
System.out.println(":: The Triangle is Not Equilateral ::");
}
//Displaying the triangle is Scalene triangle or not
public void Scalene()
{
double lengthA=distance(getCoodX1(),getCoodY1(), getCoodX2(), getCoodY2());
double lengthB=distance(getCoodX2(),getCoodY2(), getCoodX3(), getCoodY3());
double lengthC=distance(getCoodX3(),getCoodY3(), getCoodX1(), getCoodY1());
if((lengthA!=lengthB) && (lengthB!=lengthC) && (lengthC!=lengthA) )
{
System.out.println(":: The Triangle is Scalene ::");
}
else
System.out.println(":: The Triangle is Not Scalene ::");
}
//Checking the triangle is right angled or not
public boolean RightTraingle()
{
double xDiff1=getCoodX2()-getCoodX1();
double yDiff1=getCoodY2()-getCoodY1();
double angleC=Math.atan2(yDiff1, xDiff1)*(180/Math.PI);
double xDiff2=getCoodX3()-getCoodX2();
double yDiff2=getCoodY3()-getCoodY2();
5. double angleA=Math.atan2(yDiff2, xDiff2)*(180/Math.PI);
double xDiff3=getCoodX1()-getCoodX3();
double yDiff3=getCoodY1()-getCoodY3();
double angleB=Math.atan2(yDiff3, xDiff3)*(180/Math.PI);
if(angleA==90 || angleB==90 || angleC==90)
return true;
else
return false;
}
//Checking the triangle is Acute angled or not
public boolean Acute()
{
double xDiff1=getCoodX2()-getCoodX1();
double yDiff1=getCoodY2()-getCoodY1();
double angleC=Math.atan2(yDiff1, xDiff1)*(180/Math.PI);
double xDiff2=getCoodX3()-getCoodX2();
double yDiff2=getCoodY3()-getCoodY2();
double angleA=Math.atan2(yDiff2, xDiff2)*(180/Math.PI);
double xDiff3=getCoodX1()-getCoodX3();
double yDiff3=getCoodY1()-getCoodY3();
double angleB=Math.atan2(yDiff3, xDiff3)*(180/Math.PI);
if(angleA<90 && angleB<90 && angleC<90)
return true;
else
return false;
}
}
_____________________________________________
MyMain.java
import java.text.DecimalFormat;
public class MyMain {
public static void main(String[] args) {
//DecimalFormat Object is used to format the number
DecimalFormat df=new DecimalFormat("#.##");
6. System.out.println("________Traingle#1________");
//Creating TriangleU210 class Object by passing parameters
TriangleU210 tri=new TriangleU210(2.5, 2, 4.2, 3,5, 3.5);
//Displaying the area of the triangle
System.out.println("Area of the Triangle :"+df.format(tri.getArea()));
//Displaying the perimeter of the triangle
System.out.println("Perimter of the Traingle :"+df.format(tri.getPerimeter()));
//calling the Equilateral() method on the TriangleU210 object
tri.Equilateral();
//calling the Isosceles() method on the TriangleU210 object
tri.Isosceles();
//calling the Scalene() method on the TriangleU210 object
tri.Scalene();
//calling the RightTraingle() method on the TriangleU210 object
boolean rbool=tri.RightTraingle();
if(rbool==true)
System.out.println(":: Triangle is Right Angled ::");
else
System.out.println(":: Triangle is Not Right Angled ::");
//calling the Acute() method on the TriangleU210 object
boolean abool=tri.Acute();
if(abool==true)
System.out.println(":: Triangle is Acute Angled ::");
else
System.out.println(":: Triangle is Not Acute Angled ::");
System.out.println(" ________Traingle#2________");
7. //Creating TriangleU210 class Object by passing parameters
TriangleU210 trione=new TriangleU210(-3, 2, 2, 1,-2, -3);
//Displaying the area of the triangle
System.out.println("Area of the Triangle :"+df.format(trione.getArea()));
//Displaying the perimeter of the triangle
System.out.println("Perimter of the Traingle :"+df.format(trione.getPerimeter()));
//calling the Equilateral() method on the TriangleU210 object
trione.Equilateral();
//calling the Isosceles() method on the TriangleU210 object
trione.Isosceles();
//calling the Scalene() method on the TriangleU210 object
trione.Scalene();
//calling the RightTraingle() method on the TriangleU210 object
boolean rbool1=tri.RightTraingle();
if(rbool1==true)
System.out.println(":: Triangle is Right Angled ::");
else
System.out.println(":: Triangle is Not Right Angled ::");
//calling the Acute() method on the TriangleU210 object
boolean abool1=tri.Acute();
if(abool==true)
System.out.println(":: Triangle is Acute Angled ::");
else
System.out.println(":: Triangle is Not Acute Angled ::");
System.out.println(" ________Traingle#3________");
//Creating TriangleU210 class Object by passing parameters
TriangleU210 tritwo=new TriangleU210(3, 0, 6, 0,4.5, -2.6);
8. //Displaying the area of the triangle
System.out.println("Area of the Triangle :"+df.format(tritwo.getArea()));
//Displaying the perimeter of the triangle
System.out.println("Perimter of the Traingle :"+df.format(tritwo.getPerimeter()));
//calling the Equilateral() method on the TriangleU210 object
tritwo.Equilateral();
//calling the Isosceles() method on the TriangleU210 object
tritwo.Isosceles();
//calling the Scalene() method on the TriangleU210 object
tritwo.Scalene();
//calling the RightTraingle() method on the TriangleU210 object
boolean rbool2=tri.RightTraingle();
if(rbool1==true)
System.out.println(":: Triangle is Right Angled ::");
else
System.out.println(":: Triangle is Not Right Angled ::");
//calling the Acute() method on the TriangleU210 object
boolean abool2=tri.Acute();
if(abool==true)
System.out.println(":: Triangle is Acute Angled ::");
else
System.out.println(":: Triangle is Not Acute Angled ::");
}
}
_____________________________________________
Output:
________Traingle#1________
Area of the Triangle :0.03
Perimter of the Traingle :5.83
:: The Triangle is Not Equilateral ::
9. :: The Triangle is Not Isosceles ::
:: The Triangle is Scalene ::
:: Triangle is Not Right Angled ::
:: Triangle is Acute Angled ::
________Traingle#2________
Area of the Triangle :12
Perimter of the Traingle :15.85
:: The Triangle is Not Equilateral ::
:: The Triangle is Isosceles ::
:: The Triangle is Not Scalene ::
:: Triangle is Not Right Angled ::
:: Triangle is Acute Angled ::
________Traingle#3________
Area of the Triangle :3.9
Perimter of the Traingle :9
:: The Triangle is Not Equilateral ::
:: The Triangle is Isosceles ::
:: The Triangle is Not Scalene ::
:: Triangle is Not Right Angled ::
:: Triangle is Acute Angled ::
________________________________________Thank You
Solution
TriangleU210.java
public class TriangleU210 {
//Declaring instance variables
private double coodX1,coodY1,coodX2,coodY2,coodX3,coodY3;
//Default Constructor
public TriangleU210() {
this.coodX1=0;
this.coodY1=0;
this.coodX2=0;
this.coodY2=10;
11. this.coodY2 = coodY2;
}
public double getCoodX3() {
return coodX3;
}
public void setCoodX3(double coodX3) {
this.coodX3 = coodX3;
}
public double getCoodY3() {
return coodY3;
}
public void setCoodY3(double coodY3) {
this.coodY3 = coodY3;
}
//This method will calculate the distance between the point
public double distance(double x1,double y1,double x2,double y2)
{
return Math.sqrt(Math.pow((x2-x1),2)+Math.pow((y2-y1),2));
}
//This method will calculate the angle between the two points
public double angleOfPoints(double x1,double y1,double x2,double y2)
{
double xDiff=x2-x1;
double yDiff=y2-y1;
double angle=Math.atan2(yDiff, xDiff)*(180/Math.PI);
return angle;
}
//This method will calculate the area of the triangle
public double getArea()
{
double lengthA=distance(getCoodX1(),getCoodY1(), getCoodX2(), getCoodY2());
double lengthB=distance(getCoodX2(),getCoodY2(), getCoodX3(), getCoodY3());
double lengthC=distance(getCoodX3(),getCoodY3(), getCoodX1(), getCoodY1());
double S=(lengthA+lengthB+lengthC)/2;
//Calculating the area
12. double area=Math.sqrt(S*(S-lengthA)*(S-lengthB)*(S-lengthC));
return area;
}
//This method will calculate the Perimeter of the triangle
public double getPerimeter()
{
double lengthA=distance(getCoodX1(),getCoodY1(), getCoodX2(), getCoodY2());
double lengthB=distance(getCoodX2(),getCoodY2(), getCoodX3(), getCoodY3());
double lengthC=distance(getCoodX3(),getCoodY3(), getCoodX1(), getCoodY1());
//Calculating the perimter
double S=(lengthA+lengthB+lengthC);
return S;
}
//Displaying the triangle is isosceles triangle or not
public void Isosceles()
{
double lengthA=distance(getCoodX1(),getCoodY1(), getCoodX2(), getCoodY2());
double lengthB=distance(getCoodX2(),getCoodY2(), getCoodX3(), getCoodY3());
double lengthC=distance(getCoodX3(),getCoodY3(), getCoodX1(), getCoodY1());
if((lengthA==lengthB) || (lengthB==lengthC) || (lengthC==lengthA) )
{
System.out.println(":: The Triangle is Isosceles ::");
}
else
System.out.println(":: The Triangle is Not Isosceles ::");
}
//Displaying the triangle is Equilateral triangle or not
public void Equilateral()
{
double lengthA=distance(getCoodX1(),getCoodY1(), getCoodX2(), getCoodY2());
double lengthB=distance(getCoodX2(),getCoodY2(), getCoodX3(), getCoodY3());
double lengthC=distance(getCoodX3(),getCoodY3(), getCoodX1(), getCoodY1());
if((lengthA==lengthB) && (lengthB==lengthC) && (lengthC==lengthA) )
{
System.out.println(":: The Triangle is Equilateral ::");
13. }
else
System.out.println(":: The Triangle is Not Equilateral ::");
}
//Displaying the triangle is Scalene triangle or not
public void Scalene()
{
double lengthA=distance(getCoodX1(),getCoodY1(), getCoodX2(), getCoodY2());
double lengthB=distance(getCoodX2(),getCoodY2(), getCoodX3(), getCoodY3());
double lengthC=distance(getCoodX3(),getCoodY3(), getCoodX1(), getCoodY1());
if((lengthA!=lengthB) && (lengthB!=lengthC) && (lengthC!=lengthA) )
{
System.out.println(":: The Triangle is Scalene ::");
}
else
System.out.println(":: The Triangle is Not Scalene ::");
}
//Checking the triangle is right angled or not
public boolean RightTraingle()
{
double xDiff1=getCoodX2()-getCoodX1();
double yDiff1=getCoodY2()-getCoodY1();
double angleC=Math.atan2(yDiff1, xDiff1)*(180/Math.PI);
double xDiff2=getCoodX3()-getCoodX2();
double yDiff2=getCoodY3()-getCoodY2();
double angleA=Math.atan2(yDiff2, xDiff2)*(180/Math.PI);
double xDiff3=getCoodX1()-getCoodX3();
double yDiff3=getCoodY1()-getCoodY3();
double angleB=Math.atan2(yDiff3, xDiff3)*(180/Math.PI);
if(angleA==90 || angleB==90 || angleC==90)
return true;
else
return false;
}
//Checking the triangle is Acute angled or not
public boolean Acute()
14. {
double xDiff1=getCoodX2()-getCoodX1();
double yDiff1=getCoodY2()-getCoodY1();
double angleC=Math.atan2(yDiff1, xDiff1)*(180/Math.PI);
double xDiff2=getCoodX3()-getCoodX2();
double yDiff2=getCoodY3()-getCoodY2();
double angleA=Math.atan2(yDiff2, xDiff2)*(180/Math.PI);
double xDiff3=getCoodX1()-getCoodX3();
double yDiff3=getCoodY1()-getCoodY3();
double angleB=Math.atan2(yDiff3, xDiff3)*(180/Math.PI);
if(angleA<90 && angleB<90 && angleC<90)
return true;
else
return false;
}
}
_____________________________________________
MyMain.java
import java.text.DecimalFormat;
public class MyMain {
public static void main(String[] args) {
//DecimalFormat Object is used to format the number
DecimalFormat df=new DecimalFormat("#.##");
System.out.println("________Traingle#1________");
//Creating TriangleU210 class Object by passing parameters
TriangleU210 tri=new TriangleU210(2.5, 2, 4.2, 3,5, 3.5);
//Displaying the area of the triangle
System.out.println("Area of the Triangle :"+df.format(tri.getArea()));
//Displaying the perimeter of the triangle
System.out.println("Perimter of the Traingle :"+df.format(tri.getPerimeter()));
15. //calling the Equilateral() method on the TriangleU210 object
tri.Equilateral();
//calling the Isosceles() method on the TriangleU210 object
tri.Isosceles();
//calling the Scalene() method on the TriangleU210 object
tri.Scalene();
//calling the RightTraingle() method on the TriangleU210 object
boolean rbool=tri.RightTraingle();
if(rbool==true)
System.out.println(":: Triangle is Right Angled ::");
else
System.out.println(":: Triangle is Not Right Angled ::");
//calling the Acute() method on the TriangleU210 object
boolean abool=tri.Acute();
if(abool==true)
System.out.println(":: Triangle is Acute Angled ::");
else
System.out.println(":: Triangle is Not Acute Angled ::");
System.out.println(" ________Traingle#2________");
//Creating TriangleU210 class Object by passing parameters
TriangleU210 trione=new TriangleU210(-3, 2, 2, 1,-2, -3);
//Displaying the area of the triangle
System.out.println("Area of the Triangle :"+df.format(trione.getArea()));
//Displaying the perimeter of the triangle
System.out.println("Perimter of the Traingle :"+df.format(trione.getPerimeter()));
//calling the Equilateral() method on the TriangleU210 object
trione.Equilateral();
16. //calling the Isosceles() method on the TriangleU210 object
trione.Isosceles();
//calling the Scalene() method on the TriangleU210 object
trione.Scalene();
//calling the RightTraingle() method on the TriangleU210 object
boolean rbool1=tri.RightTraingle();
if(rbool1==true)
System.out.println(":: Triangle is Right Angled ::");
else
System.out.println(":: Triangle is Not Right Angled ::");
//calling the Acute() method on the TriangleU210 object
boolean abool1=tri.Acute();
if(abool==true)
System.out.println(":: Triangle is Acute Angled ::");
else
System.out.println(":: Triangle is Not Acute Angled ::");
System.out.println(" ________Traingle#3________");
//Creating TriangleU210 class Object by passing parameters
TriangleU210 tritwo=new TriangleU210(3, 0, 6, 0,4.5, -2.6);
//Displaying the area of the triangle
System.out.println("Area of the Triangle :"+df.format(tritwo.getArea()));
//Displaying the perimeter of the triangle
System.out.println("Perimter of the Traingle :"+df.format(tritwo.getPerimeter()));
//calling the Equilateral() method on the TriangleU210 object
tritwo.Equilateral();
//calling the Isosceles() method on the TriangleU210 object
tritwo.Isosceles();
17. //calling the Scalene() method on the TriangleU210 object
tritwo.Scalene();
//calling the RightTraingle() method on the TriangleU210 object
boolean rbool2=tri.RightTraingle();
if(rbool1==true)
System.out.println(":: Triangle is Right Angled ::");
else
System.out.println(":: Triangle is Not Right Angled ::");
//calling the Acute() method on the TriangleU210 object
boolean abool2=tri.Acute();
if(abool==true)
System.out.println(":: Triangle is Acute Angled ::");
else
System.out.println(":: Triangle is Not Acute Angled ::");
}
}
_____________________________________________
Output:
________Traingle#1________
Area of the Triangle :0.03
Perimter of the Traingle :5.83
:: The Triangle is Not Equilateral ::
:: The Triangle is Not Isosceles ::
:: The Triangle is Scalene ::
:: Triangle is Not Right Angled ::
:: Triangle is Acute Angled ::
________Traingle#2________
Area of the Triangle :12
Perimter of the Traingle :15.85
:: The Triangle is Not Equilateral ::
:: The Triangle is Isosceles ::
:: The Triangle is Not Scalene ::
18. :: Triangle is Not Right Angled ::
:: Triangle is Acute Angled ::
________Traingle#3________
Area of the Triangle :3.9
Perimter of the Traingle :9
:: The Triangle is Not Equilateral ::
:: The Triangle is Isosceles ::
:: The Triangle is Not Scalene ::
:: Triangle is Not Right Angled ::
:: Triangle is Acute Angled ::
________________________________________Thank You