-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcw-lightBotMethodCalls10.peml
134 lines (101 loc) · 3.1 KB
/
cw-lightBotMethodCalls10.peml
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
exercise_id: https://codeworkout.cs.vt.edu/gym/exercises/829/practice?workout_id=1308
title: CodeWorkout LightBot Method Calls 10
external_id: CS1114_Week1SyntaxDrill10
is_public: true
experience: 50
language_list: Java
license.id: cc-sa-4.0
license.owner.email: [email protected]
license.owner.name: Stephen H. Edwards
tags.topics: CS1114, LightBot, Methods, java
tags.style: code-writing
instructions:----------
For the question below, assume we are working with a simplified LightBot that can perform the following actions
* Turn Left
* Turn Right
* Move Forward
* Jump
Each of these actions is represented by a method call:
* Turn Left --> `turnLeft()`
* Turn Right --> `turnRight()`
* Move Forward --> `moveForward()`
* Jump --> `jump()`
Just like in the LightBot puzzles, there is also a method called `spin()` that causes the LightBot to turn left four times.
In the code below, remove the method call to `spin()`. Note, this does not mean to delete the whole `spin()` method, just the call to the method.
----------
[systems]
language: Java
[assets.code.wrapper.files]
content:----------
import java.util.ArrayList;
public class syntax10 {
public static class SimpleLightBot {
private ArrayList<String> moveHistory;
public SimpleLightBot() {
moveHistory = new ArrayList<String>();
}
public String[] getMoveHistory() {
String[] a = new String[moveHistory.size()];
return moveHistory.toArray(a);
}
public void jump() {
moveHistory.add("jump");
}
public void turnLeft() {
moveHistory.add("turnLeft");
}
public void turnRight() {
moveHistory.add("turnRight");
}
public void moveForward() {
moveHistory.add("moveForward");
}
}
public static class Runner{
___
}
}
----------
[assets.code.starter.files]
content:----------
public void spin(SimpleLightBot andy)
{
andy.turnLeft();
andy.turnLeft();
andy.turnLeft();
andy.turnLeft();
}
public void run(SimpleLightBot andy)
{
spin(andy);
andy.jump();
andy.turnLeft();
}
----------
[assets.test.files]
format: java/junit
content:----------
import codeworkout.CodeWorkoutTest;
public class syntax10Test extends CodeWorkoutTest {
private syntax10.SimpleLightBot testBot;
private syntax10.Runner runner;
public void setUp() {
testBot = new syntax10.SimpleLightBot();
runner = new syntax10.Runner();
}
public void testLightBotRun() {
String[] expected = {"jump", "turnLeft"};
runner.run(testBot);
String[] testResult = testBot.getMoveHistory();
assertEquals(expected.length, testResult.length);
assertEquals(expected, testResult);
}
public void testSpinStillExists() {
String[] expected = {"turnLeft", "turnLeft", "turnLeft", "turnLeft"};
runner.spin(testBot);
String[] testResult = testBot.getMoveHistory();
assertEquals(expected.length, testResult.length);
assertEquals(expected, testResult);
}
}
----------