forked from exercism/java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBob.java
More file actions
35 lines (31 loc) · 1010 Bytes
/
Bob.java
File metadata and controls
35 lines (31 loc) · 1010 Bytes
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
/**
* Bob is a lackadasical teenager.
*/
public class Bob {
public String hey(String input) {
input = normalize(input);
if (isSilence(input))
return "Fine. Be that way!";
if (isShout(input))
return "Whoa, chill out!";
if (isQuestion(input))
return "Sure.";
return "Whatever.";
}
private static String normalize(String input) {
return input.trim();
}
private static boolean isSilence(String input) {
return input.equals("");
}
private static boolean isShout(String input) {
final String upperCased = input.toUpperCase();
final String lowerCased = input.toLowerCase();
final boolean containsSomeLetters = !lowerCased.equals(upperCased);
final boolean isAllUpperCase = upperCased.equals(input);
return (containsSomeLetters && isAllUpperCase);
}
private static boolean isQuestion(String input) {
return input.endsWith("?");
}
}