-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcw-jerooInstantiation.peml
82 lines (69 loc) · 2.19 KB
/
cw-jerooInstantiation.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
exercise_id: https://codeworkout.cs.vt.edu/gym/exercises/854/practice?workout_id=1342
title: CodeWorkout Jeroo Instantiation
external_id: edu.vt.cs.1114.jeroo_instantiation
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: Jeroo, constructors, syntax practice
tags.style: code writing
instructions:----------
The following declaration introduces a variable named `jessica`
that refers to a `Jeroo`, and also creates a new instance of the
`Jeroo` class that starts off facing the default direction.
Add parameters
to the constructor call so the Jeroo starts out facing south
with 2 flowers.
----------
[systems]
language: Java
[assets.code.wrapper.files]
content:----------
import student.micro.jeroo.CompassDirection;
import static student.micro.jeroo.CompassDirection.*;
public class Answer {
public static class Jeroo extends student.micro.jeroo.Jeroo {
private CompassDirection facing;
private int holdingFlowers;
public Jeroo() { this(EAST, 0); }
public Jeroo(int flowers) { this(EAST, flowers); }
public Jeroo(CompassDirection direction) { this(direction, 0); }
public Jeroo(CompassDirection direction, int flowers)
{
super(direction, flowers);
facing = direction;
holdingFlowers = flowers;
}
public int __getFlowers() { return holdingFlowers; }
public CompassDirection __getFacing() { return facing; }
}
public Jeroo run () {
___
return jessica;
}
}
----------
[assets.code.starter.files]
format: java/junit
content:----------
import codeworkout.*;
import student.micro.jeroo.CompassDirection;
public class AnswerTest extends CodeWorkoutTest {
private Answer.Jeroo answer;
public void setUp() {
answer = new Answer().run();
}
@Description("The Jeroo is facing south")
public void test1() {
assertEquals("The Jeroo is not facing the correct direction",
CompassDirection.SOUTH, answer.__getFacing());
}
@Description("The Jeroo is holding 2 flowers")
public void test2() {
assertEquals("The Jeroo is not holding 2 flowers",
2, answer.__getFlowers());
}
}
----------