卡夫卡卡
幼苗
共回答了15个问题采纳率:100% 举报
public class Test {
x05public static void main(String[] args) {
x05x05Rectangle r = new Rectangle(5,4);
x05x05System.out.println("Circle for rectangle is:" + r.circle());
x05x05System.out.println("Area for rectangle is:" + r.area());
x05}
}
class Rectangle{
x05private double length;
x05private double width;
x05
x05public Rectangle(double length,double width){
x05x05this.length = length;
x05x05this.width = width;
x05}
x05public double getLength() {
x05x05return length;
x05}
x05public double getWidth() {
x05x05return width;
x05}
x05public void setLength(double length) {
x05x05this.length = length;
x05}
x05public void setWidth(double width) {
x05x05this.width = width;
x05}
x05
x05public double circle(){
x05x05return 2 * (width + length);
x05}
x05
x05public double area(){
x05x05return width * length;
x05}
}
------------------------
Circle for rectangle is:18.0
Area for rectangle is:20.0
1年前
2