好的,我对编程很陌生。我的班级有一个作业,具体说明是:
“PolygonArtMaker.java 的主代码中的代码,用于在 tRef 引用的 ArtisticTurtle 上调用您的五边形方法,以使您的应用程序在运行时绘制一个五边形。”
根据我的解释,这意味着当我在 Polygon artmaker 上单击 Run 时,它还将运行 Artistic Turtle 并使用方法应用程序绘制...。
我已经尝试了一段时间,但无法弄清楚,任何帮助将不胜感激。
多边形美术师
public class PolygonArtMaker
{
public static void main(String [] a)
{
World wRef = new World( );
ArtisticTurtle tRef = new ArtisticTurtle ( wRef );
tref.forward( 50 );
}
}
使用方法应用程序绘制
public class DrawWithMethodsApp
{
public static void main(String[] a)
{
System.out.println("Hello from main!");
World wref = new World();
ArtisticTurtle tref = new ArtisticTurtle( wref );
tref.setPenColor( java.awt.Color.RED );
tref.pentagon( 2 );
tref.penUp();
tref.moveTo( 50,463);
tref.penDown();
tref.pentagon( 5 );
tref.penUp();
tref.moveTo(350,89);
tref.penDown();
tref.pentagon( 8 );
tref.penUp();
tref.moveTo( 100, 260);
tref.penDown();
tref.hexagon( 5 );
tref.penUp();
tref.moveTo( 500, 110 );
tref.penDown();
tref.hexagon( 7 );
tref.penUp();
tref.moveTo( 360, 310 );
tref.penDown();
tref.hexagon( 9 );
**Artistic Turtle **
public class ArtisticTurtle extends Turtle
{
public void hook( int numberParam )
{
System.out.println( "The hook method has been called on ArtisticTurtle "
+
this
+
"with parameter value equal to "
+
numberParam
);
}
public void pentagon( int numberParam )
{
System.out.println
("pentagon called with param "
+ numberParam);
int curLen;
curLen = (numberParam) ;
this.forward ( 10*curLen );
this.turn( 360.0/5 );
this.forward( 10*curLen );
this.turn( 360.0/5 );
this.forward( 10*curLen);
this.turn( 360.0/5 );
this.forward( 10*curLen );
this.turn( 360.0/5 );
this.forward( 10*curLen );
}
public void hexagon( int numberParam)
{
System.out.println
("hexagon called with param "
+ numberParam);
int curLen;
curLen = (numberParam) ;
this.forward( 10*curLen );
this.turn( 60 );
this.forward( 10*curLen);
this.turn( 60 );
this.forward( 10*curLen);
this.turn( 60 );
this.forward( 10*curLen);
this.turn( 60 );
this.forward( 10*curLen);
this.turn( 60 );
this.forward( 10*curLen );
}
public ArtisticTurtle( World wrefParam )
{
super( wrefParam );
}
public static void main(String[] a)
{
System.out.println("DONT RUN ArtisticTurtle!!");
System.out.println("Select DrawWithMethodsApp");
System.out.println("and RUN that!");
}
}