forked from League-Archive/IntroToJavaWorkshop
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFourSquare.java
More file actions
executable file
·47 lines (34 loc) · 957 Bytes
/
FourSquare.java
File metadata and controls
executable file
·47 lines (34 loc) · 957 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package section2;
import javax.swing.JOptionPane;
import org.jointheleague.graphical.robot.Robot;
public class FourSquare {
// 2. Create a new Robot
Robot hello = new Robot("batman");
void go() {
// 4. Make the robot move as fast as possible
hello.setSpeed(500);
// 5. Set the pen width to 5
hello.setPenWidth(5);
// 6. Use a for loop to repeat steps #7 to #8, four times..
for(int i = 0; i <4; i++) {
// 7. Set the pen color to random
hello.setRandomPenColor();
// 1. Call the drawSquare() method
drawSquare();
// 8. Turn the robot 90 degrees to the right
hello.turn(90);
}
}
void drawSquare() {
JOptionPane.showMessageDialog(null, "yay! you called the drawSquare() method!");
/* 3. Fill in the code to draw a square inside the method below. */
hello.penDown();
for(int i = 0; i <4; i++) {
hello.move(100);
hello.turn(90);
}
}
public static void main(String[] args) {
new FourSquare().go();
}
}