矩形java_编码关于矩形的东西(Java)

所以在我的在线课堂上,我必须做一些与矩形有关的事情。我对如何编辑我的主类使其使用另一个类的方法存在一些困惑。

这是项目的链接,因为你不明白我要问什么:

http://pages.eimacs.com/eimacsstatics/download/apjava/project1bj.pdf

我感到困惑的部分是为printAPRectangle添加一个定义,因为我认为我没有正确地做到这一点。

Add accessor instance methods for the three instance variables, and then

click the Compile button on the APRectangle class editor window to compile

your code and check for errors.

Reopen the definition of MainClass and insert a definition of the static

method printAPRectangle after the definition of printAPPoint. This method

should be defined in such a way that, if it is applied to the APRectangle

object whose top left corner is the APPoint object with coordinate (-5.0,3.6),

这是我的APRectangle类代码:

public class APRectangle

{

private APPoint myTopLeft;

private double myWidth;

private double myHeight;

public APRectangle( APPoint topLeft, double width, double height )

{

myTopLeft = topLeft;

myWidth = width;

myHeight = height;

}

public APPoint getTopLeft()

{

return myTopLeft;

}

public double getWidth()

{

return myWidth;

}

public double getHeight()

{

return myHeight;

}

}这是我的APPoint类:

public class APPoint {

private double myX;

private double myY;

public APPoint( double x, double y ) {

myX = x;

myY = y; }

public double getX() {

return myX; }

public void setX( double x ) {

myX = x; }

public double getY() {

return myY; }

public void setY( double y ) {

myY = y; } }

最后这里是我的主类:

public class MainClass

{

public MainClass()

{

}

public static String printAPPoint( APPoint p )

{

return "(" + p.getX() + "," + p.getY() + ")";

}

public static String printAPRectangle( APRectangle R)

{

return "[APRectangle " + printAPPoint( +

" " + getWidth() + "," + getHeight() + "]" ;

}

public static void main(String[] args)

{

APPoint p = new APPoint( 1.0, 2.0 );

APRectangle R = new APRectangle( q, 7.5, 3.6);

System.out.println( "p is " + printAPPoint( p ) );

System.out.println( "Done!" );

}

}我不知道如何去做那些问我如何编辑主类的部分,也不知道如何去输出myTopLeft,因为它是APPoint而不是普通字符串。它说我必须使用printAPPoint,但我该如何使用它?

谢谢,

罗汉

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值