纯属手打,如有错误,还请见谅。
以下代码仅供参考,自己写的,如有错误,还请见谅。
1、 文件名:Rectangle.java
public class Rectangle{
int width,height;
public Rectangle(){
width=1;
height=1;
}
public Rectangle(int w,int h){
width=w;
height=h;
}
public Rectangle(Rectangle r){
r.width=10;
r.height=20;
}
public double getArea(){
return width*height;
}
public double getPerimeter(){
return 2*(width+height);
}
public boolean equals(Rectangle r){
boolean t;
if(width==r.width && height==r.height)
t=true;
else
t=false;
return t;
}
public int getWidth(){
return width;
}
public int getHeight(){
return height;
}
public String toStrings(){
return ("矩形("+width+","+height+")");
}
public static void main(String args[]){
Rectangle r= new Rectangle(5,10);
Rectangle r1= new Rectangle();
System.out.println("验证值="+r.toStrings());