如何用java编写类 Circle(圆) 和类 Rectangle(矩形) ,
来源:学生作业帮助网 编辑:六六作业网 时间:2024/12/18 18:53:18
如何用java编写类 Circle(圆) 和类 Rectangle(矩形) ,
如何用java编写类 Circle(圆) 和类 Rectangle(矩形) ,
如何用java编写类 Circle(圆) 和类 Rectangle(矩形) ,
public class Rectangle
{
private double width;
private double length;
public double getWidth()
{
return width;
}
public void setWidth(double width)
{
this.width = width;
}
public double getLength()
{
return length;
}
public void setLength(double length)
{
this.length = length;
}
public double mianji()
{
return width*length;
}
public double zhouchang()
{
return (width+length)*2;
}
}
public class Circle
{
private double r;
public double getR()
{
return r;
}
public void setR(double r)
{
this.r = r;
}
public double zhouchang()
{
return 2*Math.PI*r;
}
public double mianji()
{
return Math.PI*r*r;
}
}