我有一个课程如下:
public class Polygon extends Shape{
private int noSides;
private int lenghts[];
public Polygon(int id,Point center,int noSides,int lengths[]) {
super(id, center);
this.noSides = noSides;
this.lenghts = lengths;
}
}
Run Code Online (Sandbox Code Playgroud)
现在,正多边形是一个多边形,其边是相等的.什么应该是我的正多边形的构造函数?
public Regularpolygon extends Polygon{
//constructor ???
}
Run Code Online (Sandbox Code Playgroud)
mis*_*tor 54
public class Polygon extends Shape {
private int noSides;
private int lenghts[];
public Polygon(int id,Point center,int noSides,int lengths[]) {
super(id, center);
this.noSides = noSides;
this.lenghts = lengths;
}
}
public class RegularPolygon extends Polygon {
private static int[] getFilledArray(int noSides, int length) {
int[] a = new int[noSides];
java.util.Arrays.fill(a, length);
return a;
}
public RegularPolygon(int id, Point center, int noSides, int length) {
super(id, center, noSides, getFilledArray(noSides, length));
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
89231 次 |
| 最近记录: |