埦写一个埴段垥Segment该垥有两个变量:两个表埳点的对象成员方法有:埲算长埶、埴条着色埵。画出UML图。java代码
UML图:
_________________
| Segment |
|_______________|
| - point1: Point|
| - point2: Point|
|_______________|
| + Segment(Point, Point)|
| + getLength(): double|
| + setColor(Color): void|
|_______________|
Java代码:
import java.awt.Color;
public class Segment {
private Point point1;
private Point point2;
public Segment(Point point1, Point point2) {
this.point1 = point1;
this.point2 = point2;
}
public double getLength() {
return point1.distance(point2);
}
public void setColor(Color color) {
// set color of the segment
}
}
``
原文地址: https://www.cveoy.top/t/topic/g0uz 著作权归作者所有。请勿转载和采集!