Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
"files.autoSave": "afterDelay",
"screencastMode.onlyKeyboardShortcuts": true,
"terminal.integrated.fontSize": 18,
"workbench.activityBar.visible": true,
"workbench.colorTheme": "Visual Studio Dark",
"workbench.fontAliasing": "antialiased",
"workbench.statusBar.visible": true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.util.Map;
import java.util.Scanner;
import java.util.concurrent.atomic.AtomicInteger;

public class App {
public static final Map<Character, Integer> letterPoints = Map.ofEntries(Map.entry('A', 1),
Expand All @@ -14,7 +15,34 @@ public class App {
Map.entry('Z', 10));

public static int wordScoreCalculator(String word) {
return 0;
int score = 0;
char[] wordChars = word.toUpperCase().toCharArray();
for (Character c:wordChars){
int letterPoint = letterPoints.entrySet().stream()
.filter(entry -> entry.getKey().equals(c))
.map(entry -> entry.getValue())
.findFirst()
.orElse(0);
score += letterPoint;
}
return score;
}

public static int lettersCalculatorVersion2(String word){
AtomicInteger score = new AtomicInteger(0);

word.toUpperCase().chars()
.filter(Character::isAlphabetic)
//containsKey() should contain an object, not integer
.mapToObj(letter -> (char) letter)
.forEachOrdered(letter -> {
if (letterPoints.containsKey(letter)){
score.getAndAdd(letterPoints.get(letter));
}else{
System.out.println("Looks like we need to add "+ letter + "to the list");
}
});
return score.getPlain();
}

public static void main(String[] args) {
Expand All @@ -23,7 +51,7 @@ public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String word = sc.nextLine();
System.out.println("Your word " + word + " will earn "
+ wordScoreCalculator(word));
+ lettersCalculatorVersion2(word));
sc.close();
}

Expand Down
Binary file not shown.