日期:2014-05-20  浏览次数:20773 次

java新手,有个简单的问题
正方形继承长方形,哪里出问题了
class Rectangle{
  private int x1;
  private int x2;
  private int y1;
  private int y2;

  public Rectangle(int x1,int x2,int y1,int y2){
  this.x1=x1;
  this.x2=x2;
  this.y1=y1;
  this.y2=y2;
  }
  public int getHeight(){
  int aHeight=0;
  aHeight=Math.abs(x1-x2);
  return aHeight;
  }
  public int getWidth(){
  int aWidth=0;
  aWidth=Math.abs(y1-y2);
  return aWidth;
  }
  public int getPerimeter(){
  int aPerimeter=0;
  aPerimeter=getHeight()*2+getWidth()*2;
  return aPerimeter;
  }
  public int getArea(){
  int aArea=0;
  aArea=getHeight()*getWidth();
  return aArea;
  }
}

class Triangle{
  private int x1;
  private int y1;
  private int x2;
  private int y2;
  private int x3;
  private int y3;
 
  public Triangle(int x1,int x2,int x3,int y1,int 

y2,int y3){
  this.x1=x1;
  this.y1=y1;
  this.x2=x2;
  this.y2=y2;
  this.x3=x3;
  this.y3=y3;
  }
  public double getFirstLength(){
  double aFirstLength=0;
  aFirstLength=Math.sqrt((x1-x2)*(x1-x2)+(y1-y2)

*(y1-y2));
  return aFirstLength;
  }
  public double getSecondLength(){
  double aSecondLength=0;
  aSecondLength=Math.sqrt((x2-x3)*(x2-x3)+(y2-

y3)*(y2-y3));
  return aSecondLength;
  }
  public double getThirdLength(){
  double aThirdLength=0;
  aThirdLength=Math.sqrt((x1-x3)*(x1-x3)+(y1-y3)

*(y1-y3));
  return aThirdLength;
  }
  public double getPerimeter(){
  double aPerimeter=0;
  aPerimeter=getFirstLength()+getSecondLength

()+getThirdLength();
  return aPerimeter;
  }
  public double getArea(){
  double aArea=0;
  double half=getPerimeter()/2;
  aArea=Math.sqrt(half*(half-getFirstLength())*
  (half-getSecondLength())*(half-

getThirdLength()));
  return aArea;
  }
}

class Circle{
  private int x1;
  private int y1;
  private int r;
  private double constant;

  public Circle(int x1,int y1,int r){
  this.x1=x1;
  this.y1=y1;
  this.r=r;
  constant=3.1415;
  }
  public int getDiameter(){
  int aDiameter=0;
  aDiameter=2*r;
  return aDiameter;
  }
  public double getPerimeter(){
  double aPerimeter=0;
  aPerimeter=constant*getDiameter();
  return aPerimeter; 
  }
  public double getArea(){
  double aArea=0;
  aArea=constant*r*r;
  return aArea;
  }
}

class LineSegment{
  private int x1;
  private int y1;
  private int x2;
  private int y2;

  public LineSegment(int x1,int y1,int x2,int y2){
  this.x1=x1;
  this.y1=y1;
  this.x2=x2;
  this.y2=y2;
  }
  public double getLineLength(){
  double aLineLength=0.0;
  aLineLength=Math.sqrt((x1-x2)*(x1-x2)+(y1-