Exemplo completo do descrito acima:
import org.junit.Test;
import static org.junit.Assert.assertEquals;
public class TabNewsExercise1Test {
@Test
public void test1() {
TabNewsExercise1 ex = new TabNewsExercise1();
assertEquals(5, ex.doExercise("teste"));
}
@Test
public void test2() {
TabNewsExercise1 ex = new TabNewsExercise1();
assertEquals(14, ex.doExercise("Iuri"));
}
@Test
public void test3() {
TabNewsExercise1 ex = new TabNewsExercise1();
assertEquals(16, ex.doExercise("tabnews"));
}
}
public class TabNewsExercise1 {
public static int doExercise(final String input) {
int score = 0;
for (char letter : input.toUpperCase().toCharArray()) {
score += Letters.valueOf(Character.toString(letter)).getLetterScore();
}
return score;
}
}
public enum Letters {
A(1),
B(3),
C(3),
D(2),
E(1),
F(4),
G(2),
H(4),
I(5),
J(8),
K(5),
L(1),
M(3),
N(5),
O(1),
P(3),
Q(10),
R(1),
S(1),
T(1),
U(3),
V(4),
W(4),
X(8),
Y(4),
Z(10);
private final int score;
private Letters(int letterScore) {
this.score = letterScore;
}
int getLetterScore() {
return score;
}
}