帮忙做一个Java程序设计题

(1) 定义接口Shape,其中包含方法double getPeremeter()求周长, double getArea()求面积;
(2) 定义一个矩形类,实现此接口,并自行扩充成员变量和方法,定义一个方法一次直接显示长和宽、面积、对角线长;
(3) 定义一个测试类,测试矩形类。

//接口
public interface Shape{
    public abstract double getPeremeter();
    public abstract double getArea();
}

//矩形类
public class MyRect implements Shape{
    private double width = 0; //宽
    private double height = 0;//长
    private double arc = 0;//对角线

    public MyRect(double width, double height){
        this.width = width;
        this.height = height;
    }
    
    @Override
    public double getPeremeter(){
        return (width + height) * 2;
    }
    
    @Override
    public double getArea(){
        return width * height;
    }
    
    public void show(){
        arc = Math.sqrt((width * width) + (height * height))
        System.out.println("长:"+ height + " 宽:" + width + " 面积:" + getArea() + " 对角线:" + arc);
    }
    
}

public class test{
    public static void main(String [] args){
        MyRect myRect = new MyRect(20, 30);
        System.out.println("周长:" + myRect.getPeremeter());
        System.out.println("面积:" + myRect.getArea());
        myRect.show();
    }
}

追问

怎么做的呀?

温馨提示:答案为网友推荐,仅供参考
第1个回答  2018-10-26
我可以试试追问

好的

第2个回答  2018-10-26
自己好好把Java的基础看一下随随便便就能做出来 这个又没有什么难度追问

初学者不会怎么弄

相似回答