1.设计一个形状类(接口)Shape,方法:求周长和求面积
形状类(接口)的子类(实现类):
package com.hp.demo7;
//接口
public interface Shape {
//计算面积的方法
double getArea();
//计算周长的方法
double getPerimeter();
}
2. Rect(矩形)
package com.hp.demo7;
//设计一个形状类(接口)Shape,方法:求周长和求面积
//形状类
//矩形类
public class Rect implements Shape{
private double width; //宽度
private double height; //高
public double getWidth() {
return width;
}
public void setWidth(double width) {
this.width = width;
}
public double getHeight() {
return height;
}
public void setHeight(double height) {
this.height = height;
}
//一个有参构造,将用于子类正方形
public Rect(double width){
this.width = width;
}
//有参构造
public Rect(double width, double height) {
this.width = width;
this.height = height;
}
@Override
publi