-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcw-genericsGenericMethod2.peml
70 lines (59 loc) · 1.71 KB
/
cw-genericsGenericMethod2.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
exercise_id: https://codeworkout.cs.vt.edu/gym/exercises/468/practice?workout_id=680
title: Generics - Generic Method 2
external_id: cw-x51
is_public: true
experience: 10
language_list: Java
license.id: cc-sa-4.0
license.owner.email: [email protected]
license.owner.name: Stephen Edwards
tags.topics: generic, char, int, String
tags.style: coding problem
instructions:----------
You have been handed a mysterious piece of data by an unknown person. Judging
by his shifty eyes and maniacal laughter you don't think he can be trusted.
Complete the below method to tell you the type for this unknown data.
The example already implemented can be adapted for other wrapper classes as well.
Complete the method to analyze String, Character, and Double.
----------
[systems]
language: Java
[assets.code.wrapper.files]
content:----------
public class Answer <E>
{
___
}
----------
[assets.code.starter.files]
content:----------
public String whatAmI(E e){
//.getClass() returns the
runtime class of an object
//.equals() determines whether two objects
are equivalent
//by calling a new static instance of a wrapper object
we can analyze
//it's class type and compare it to the variable passed
in
if(e.getClass().equals(new Integer(1).getClass())){
return
"Integer";
}else{
return "Who knows!";
}
}
----------
[assets.test.files]
format: text/csv-unquoted
pattern_actual: subject.whatAmI({{e}})
content:----------
e,expected,description
"1",""Integer"",example
""(╯°□°)╯︵ ┻━┻)"",""String""
""┬─┬ノ( º _ ºノ)"",""String""
""Boring String Example"",""String""
"'c'",""Character""
"2.2",""Double""
"new Object()",""Who knows!""
----------