-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcw-whileLoopsWithRelationalOperators1.peml
106 lines (80 loc) · 2.48 KB
/
cw-whileLoopsWithRelationalOperators1.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
exercise_id: https://codeworkout.cs.vt.edu/gym/exercises/917/practice?workout_id=1402
title: CodeWorkout While Loops with Relational Operators 1
external_id: CS1114_Week4SyntaxDrill_1
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, Jeroo, loop, java, relational
tags.style: code writing
instructions:----------
For this question, we will be working with a subclass of Jeroo called CountingJeroo that tracks the number of hops it has peformed.
You can get the number of hops performed so far by calling the `getHopCount()` method.
Below is a while loop with using a Jeroo named `imani`.
Currently, this loop will cause the jeroo to hop 10 times.
Change the conditon so that the jeroo will only hop five times instead.
----------
[systems]
language: Java
[assets.code.wrapper.files]
content:----------
import student.micro.jeroo.Jeroo;
import student.micro.jeroo.RelativeDirection;
import static student.micro.jeroo.RelativeDirection.*;
import java.util.ArrayList;
public class syntax1 {
public static class CountingJeroo extends Jeroo {
public int hopCount;
public CountingJeroo() {
this.hopCount = 0;
}
public int getHopCount() {
return hopCount;
}
public boolean willHop() {
return hopCount < 10;
}
@Override
public void hop() {
hopCount++;
}
@Override
public void hop(int numHops) {
hopCount= hopCount + numHops;
}
}// end testJeroo
public static class Runner {
___
}// end runner
}
----------
[assets.code.starter.files]
content:----------
public void question1(CountingJeroo imani)
{
while (imani.getHopCount() < 10)
{
imani.hop();
}
}
----------
[assets.test.files]
format: java/junit
content:----------
import codeworkout.CodeWorkoutTest;
import codeworkout.Description;
import codeworkout.Hint;
public class syntax1Test extends CodeWorkoutTest {
@Description("Checks jeroo stops after 5 hops")
public void test1() {
syntax1.CountingJeroo testJ = new syntax1.CountingJeroo();
int expectedHops = 5;
syntax1.Runner run = new syntax1.Runner();
run.question1(testJ);
assertEquals("Jeroo should hop "+expectedHops+" times. "
+ "Hopped: "+testJ.getHopCount()+" times", expectedHops, testJ.getHopCount());
}
}
----------