forked from mirandaio/codingbat
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscoreUp.java
More file actions
20 lines (18 loc) · 755 Bytes
/
scoreUp.java
File metadata and controls
20 lines (18 loc) · 755 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
/* The "key" array is an array containing the correct answers to an exam,
* like {"a", "a", "b", "b"}. the "answers" array contains a student's
* answers, with "?" representing a question left blank. The two arrays are
* not empty and are the same length. Return the score for this array of
* answers, giving +4 for each correct answer, -1 for each incorrect answer,
* and +0 for each blank answer.
*/
public int scoreUp(String[] key, String[] answers) {
int score = 0;
for(int i = 0; i < key.length; i++) {
if(key[i].charAt(0) == answers[i].charAt(0)) {
score += 4;
} else if(answers[i].charAt(0) != '?') {
score -= 1;
}
}
return score;
}