Skip to content

Commit 456097f

Browse files
committed
Updated Spiral to surface runtime exception
1 parent 8410cd6 commit 456097f

2 files changed

Lines changed: 26 additions & 9 deletions

File tree

  • src/main/java/org/teachingkidsprogramming

src/main/java/org/teachingkidsprogramming/recipes/completed/section01forloops/Spiral.java

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import org.teachingextensions.logo.ColorWheel;
44
import org.teachingextensions.logo.PenColors;
55
import org.teachingextensions.logo.Tortoise;
6+
import org.teachingextensions.windows.MessageBox;
67

78
public class Spiral
89
{
@@ -21,12 +22,19 @@ public static void main(String[] args)
2122
// Do the following 75 times --#3
2223
for (int i = 0; i < 75; i++)
2324
{
24-
// Change the color of the line the tortoise draws the next color on the Color Wheel --#6
25-
Tortoise.setPenColor(ColorWheel.getNextColor());
26-
// Move the tortoise 5 times the current line number you are drawing --#5
27-
Tortoise.move(i * 5);
28-
// Turn the tortoise 1/3 of 360 degrees to the right --#2
29-
Tortoise.turn(360.0 / 3);
25+
try
26+
{
27+
// Change the color of the line the tortoise draws the next color on the Color Wheel --#6
28+
Tortoise.setPenColor(ColorWheel.getNextColor());
29+
// Move the tortoise 5 times the current line number you are drawing --#5
30+
Tortoise.move(i * 5);
31+
// Turn the tortoise 1/3 of 360 degrees to the right --#2
32+
Tortoise.turn(360.0 / 3);
33+
}
34+
catch (RuntimeException re)
35+
{
36+
MessageBox.showMessage("Hold up: " + re);
37+
}
3038
}
3139
}
3240
}
Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package org.teachingkidsprogramming.section01forloops;
22

3+
import org.teachingextensions.windows.MessageBox;
4+
35
public class Spiral
46
{
57
public static void main(String[] args)
@@ -10,9 +12,16 @@ public static void main(String[] args)
1012
// Add Violet to the Color Wheel --#8
1113
// Add Purple to the Color Wheel --#9
1214
// Do the following 75 times --#3.1
13-
// Change the pen color of the line the tortoise draws the next color on the Color Wheel --#6
14-
// Move the tortoise 5 times the current line number you are drawing --#5
15-
// Turn the tortoise 1/3 of 360 degrees to the right --#2
15+
try
16+
{
17+
// Change the pen color of the line the tortoise draws the next color on the Color Wheel --#6
18+
// Move the tortoise 5 times the current line number you are drawing --#5
19+
// Turn the tortoise 1/3 of 360 degrees to the right --#2
20+
}
21+
catch (RuntimeException re)
22+
{
23+
MessageBox.showMessage("Hold up: " + re);
24+
}
1625
// Repeat --#3.2
1726
}
1827
}

0 commit comments

Comments
 (0)