You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
30 lines
801 B
30 lines
801 B
package tiaozhanti;
|
|
|
|
/**
|
|
* 椭圆形类(用于图形转换)
|
|
*/
|
|
public class Oval implements Shape {
|
|
private String color;
|
|
private double semiMajorAxis; // 长半轴
|
|
private double semiMinorAxis; // 短半轴
|
|
|
|
public Oval(String color, double semiMajorAxis, double semiMinorAxis) {
|
|
this.color = color;
|
|
this.semiMajorAxis = semiMajorAxis;
|
|
this.semiMinorAxis = semiMinorAxis;
|
|
}
|
|
|
|
@Override
|
|
public String getColor() {
|
|
return color;
|
|
}
|
|
|
|
@Override
|
|
public double getArea() {
|
|
return Math.PI * semiMajorAxis * semiMinorAxis; // 椭圆面积=πab
|
|
}
|
|
|
|
// getter
|
|
public double getSemiMajorAxis() { return semiMajorAxis; }
|
|
public double getSemiMinorAxis() { return semiMinorAxis; }
|
|
} |