次のコード:
import java.util.ArrayList;
import java.awt.Point;
public class Polygon{
ArrayList<Point> points;
//constructs polygon without points
public Polygon() {
points = new ArrayList<Point>();
}
/*
* adds a point to points
*/
public void addPoint(Point){
points.add(Point);
}
public void draw(){
for(int i = 0; i < points.size(); i++){
if(i == 0){
points.get(0).draw()
}else{
points.get(i).draw()
Line line = new Line(points.get(i-1).getX(), points.get(i-1).getY(), points.get(i).getX(), points.get(i).getY());
line.draw();
}
}
if(points.size() >= 2){
Line line = new Line(points.get(-1).getX(), points.get(-1).getY(), points.get(-2).getX(), points.get(-2).getY());
line.draw();
}
}
}
例外メッセージが表示されます:
<identifier> expected for public void addPoint(Point)
理由がわかりませんか?これらの識別子は通常、保持するオブジェクトを ArrayList に伝えるために必要ですよね?