首页 > 其它 > 题目详情
如何用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;
}
}
优质解答
{
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;
}
}
本题链接: