-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcw-usingParameters1.peml
110 lines (79 loc) · 2.27 KB
/
cw-usingParameters1.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
exercise_id: https://codeworkout.cs.vt.edu/gym/exercises/841/practice?workout_id=1334
title: CodeWorkout Using Parameters 1
external_id: CS1114_Week2SyntaxDrill6
is_public: true
experience: 50
language_list: Java
license.id: cc-sa-4.0
license.owner.email: [email protected]
license.owner.name: codeworkout
tags.topics: CS1114, Parameters, Methods, java
tags.style: code-writing
instructions:----------
For this problem assume you have access to a Person class defined here:
public class Person{
public String name;
private int age;
public void setAge(int a){
age = a;
}
public void setName(String n){
name = n;
}
}
Below you've been given a method and a Person object has been created.
Using the methods defined above, set age to 42 and name to "Peter".
----------
[systems]
language: Java
[assets.code.wrapper.files]
content:----------
public class syntax6to7 {
public static class Person{
public String name;
private int age;
public void setAge(int a){
age = a;
}
public void setName(String n){
name = n;
}
public String getName() {
return name;
}
public int getAge() {
return age;
}
}
public static class Runner{
private Person peter;
___
public Person run() {
peter = new Person();
setAgeAndName(peter);
return peter;
}
}
}
----------
[assets.code.starter.files]
content:----------
public void setAgeAndName(Person p) {
___
}
----------
[assets.test.files]
format: java/junit
content:----------
import codeworkout.CodeWorkoutTest;
public class syntax6to7Test extends CodeWorkoutTest {
public void testMethodsHaveBeenCalledCorrectly() {
syntax6to7.Runner runner = new syntax6to7.Runner();
syntax6to7.Person testPerson = runner.run();
String expectedName = "Peter";
int expectedAge = 42;
assertEquals("Name has not been set correctly", expectedName, testPerson.getName());
assertEquals("Age has not been set correctly", expectedAge, testPerson.getAge());
}
}
----------