我需要实现一个三角形类,我坚持比较边的长度以确定三角形是否确实是等腰。这是我到目前为止所拥有的:
public class TriangleIsosceles {
private Point cornerA;
private Point cornerB;
private Point cornerC;
private int x1;
private int y1;
private int x2;
private int y2;
private int x3;
private int y3;
public TriangleIsosceles(){
cornerA = new Point(0,0);
cornerB = new Point(10,0);
cornerC = new Point(5,5);
}
public TriangleIsosceles(int x1,int y1,int x2,int y2,int x3,int y3){
cornerA = new Point(x1,y1);
cornerB = new Point(x2,y2);
cornerC = new Point(x3,y3);
}
public String isIsosceles(String isIsosceles){
return isIsosceles;
}
}
我使用的Point
对象是这样的:
public class Point {
private int x;
private int y;
public Point(){
this(0,0);
}
public Point(int x, int y){
this.x = x;
this.y = y;
}
public void setX(int x){
this.x=x;
}
public void setY(int y){
this.y=y;
}
public void printPoint(){
System.out.println(x + y);
}
public String toString(){
return "x = "+x+" y = "+y;
}
}
在另一个类 ( LineSegment
) 中,我创建了一个length()
确定两点距离的方法。看起来像:
public double length() {
double length = Math.sqrt(Math.pow(x1-x2,2) + Math.pow(y1-y2,2));
return length;
}
我如何使用这种方法来帮助我在TriangleIsosceles
课堂上找到三角形的长度?
我知道我需要看看是否(lenghtAB == lengthBC || lengthBC == lenghtCA || lengthAB == lengthCA)
。