java矩形类

public class Rectangle {

    private double width;
    private double length;

    public double area(){
        double s;
        s = width * length;
        return s;
    }
    public double perimeter(){
        double c;
        c = (width + length) * 2;
        return c;
    }
    public void set(double width, double length){
        this.length = length;
        this.width = width;
    }
    public void get(){
        System.out.println("area = " + area());
        System.out.println("perimeter = " + perimeter());
    }
    public static void main(String [] args){
        double x,y;
        Scanner in = new Scanner(System.in 

);
        Rectangle r = new Rectangle();
        System.out.println("input wide and length here: ");
        x = in.nextDouble();
        y = in.nextDouble();
        r.set(x,y);
        r.get();
    }
}

 

posted @ 2019-09-18 19:02  季英杰  阅读(1370)  评论(0编辑  收藏  举报