The following questions were asked for the university assignment.
Create a TurtleTrap4 class with the method public void setColor (java.awt.Colorc) added to hide information.
In addition, create a TurtleTrap 4 class object using the main method and change the color of the pen by calling the setColor method.
So I programmed it as follows, but an error was printed.
public class TurtleTrap4{
US>Turtle;
int x, y;
int dx, dy;
public void init(int xpos, int xpos, int xspeed, int xspeed) {
This.x = xpos;
This.y = ypos;
This.dx = xspeed;
This.dy = yspeed;
This.t = new Turtle();
This.t.move(xpos,ypos);
This.t.penDown();
}
public void setColor (java.awt.Colorc)
public void step(){
if (this.x<20||340<this.x)
This.dx = -this.dx;
if (this.y<20||340<this.y)
This.dy=-this.dy;
this.x + = this.dx;
this.y + = this.dy;
This.t.move(this.x, this.y);
}
public static void main(String[]args) {
TurtleTrap4trapA = new TurtleTrap4();
trapA.init(100,200,10,5);
TurtleTrap4trapB = new TurtleTrap4();
trapB.init(150, 250, -10, 3);
setColor (RED);
while(true){
trapA.step();
trapB.step();
}
}
}
Error Message
TurtleTrap4.java:17:Error: ';' missing
public void setColor (java.awt.Colorc)
^
US>Error
What does this mean?
I'm a beginner who just started java in class last week, and I think there are many things that I don't understand about grammar, but I'd appreciate it if you could tell me where to correct it.
(Mainly, I would appreciate it if you could give me a hint on how to program public void setColor (java.awt.Colorc).
Thank you for your cooperation.
java
The code in the question text does not have the body of the method, so there is a compilation error.
Method declaration requires the body of the method (8.4.Method Declarations), and the body of the method is a semicolon ( I think the In other words:;
) or a block of code ({}
) (setColor
method will be implemented in this class, so I will add a code block (not a semicolon).public static void setColor(java.awt.Colorc){
// Implement actions when a method is called here
}
© 2024 OneMinuteCode. All rights reserved.