说我想创建一个由线,圆,方形等组成的各种形状 对于线,我要求4个坐标(x,y)(x,y);java使用抽象类
然后我有一个不同的类称为点,它必须包含 2个字段:int x,y。 它必须有一个构造函数来初始化它的字段的值和所需的get方法来读取这些值。
形状这是一个抽象类可以扩展所有形状。它应该包含形状必须具有的所有方法的签名。在扩展这个抽象类的每个类中,每个方法的实现可能不同。
然后另一个类线这是一个形状(延伸的部分),它应该有以下字段:
- String TYPE = "Line"
- MyPoint p1,p2
- Constructors
- get methods for class fields such as getP1()
- Length() : calculates the length of a line returning a double rounded to two decimal points
- Area() : which will return a the value zero as double
- renderShape(Graphics2D g2d) : used to draw the line to the screen. This method is provided for you, no need to edit it.
- printDetails(): will print the shape details , check typical input/output
我只是游荡你将如何能够从原始类获得的坐标,并打印出来感谢:)
闻起来像功课,不工作。 – 2011-03-09 18:24:53
你的问题似乎有点不清楚,我觉得答案可能部分取决于你如何实现Shape或你认为你原来的类是什么。这听起来像你只是想访问p1和p2中的坐标并打印它们? – Cooper 2011-03-09 18:26:48
为了获得灵感,您可能需要查看['java.awt.geom']中的类层次结构(http://download.oracle.com/javase/6/docs/api/java/awt/geom/package- tree.html)(与'java.awt.Shape'和'java.awt'中的其他类一起)。 – 2011-03-09 18:50:50