From 309344346e4122ad8fa68b72eed76fe3c2496dc0 Mon Sep 17 00:00:00 2001 From: Richard Persson Date: Wed, 6 Aug 2025 17:14:05 +0200 Subject: [PATCH 1/2] Completed Excercise --- src/main/java/com/booleanuk/Scrabble.java | 43 +++++++++++++++++++++-- 1 file changed, 41 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/booleanuk/Scrabble.java b/src/main/java/com/booleanuk/Scrabble.java index 88108a8..30e2a3c 100644 --- a/src/main/java/com/booleanuk/Scrabble.java +++ b/src/main/java/com/booleanuk/Scrabble.java @@ -1,12 +1,51 @@ package com.booleanuk; +import com.sun.source.tree.ArrayTypeTree; + +import java.util.*; + public class Scrabble { - public Scrabble(String word) { + private String word; + public Scrabble(String word) { + this.word = word; } public int score() { - return -1; + + if(this.word == null || this.word.isEmpty() || this.word.isBlank() || this.word.equals("\n\r\t\b\f")) + return 0; + + //Tildeler poeng til vær bokstav + ArrayList group1 = new ArrayList<>(List.of('A','E','I','U','O','U','L','N','R','S','T')); + ArrayList group2 = new ArrayList<>(List.of('D', 'G')); + ArrayList group3 = new ArrayList<>(List.of('B', 'C', 'M', 'P')); + ArrayList group4 = new ArrayList<>(List.of('F', 'H', 'V', 'W', 'Y')); + ArrayList group5 = new ArrayList<>(List.of('K')); + ArrayList group8 = new ArrayList<>(List.of('J', 'X')); + ArrayList group10 = new ArrayList<>(List.of('Q', 'Z')); + ArrayList group11 = new ArrayList<>(List.of('{', '}','[',']')); + + HashMap map = new HashMap<>(); + group1.forEach(x-> map.put(x,1)); + group2.forEach(x-> map.put(x,2)); + group3.forEach(x-> map.put(x,3)); + group4.forEach(x-> map.put(x,4)); + group5.forEach(x-> map.put(x,5)); + group8.forEach(x-> map.put(x,8)); + group10.forEach(x-> map.put(x,10)); + + int count = 0; + //Deler opp word i bokstaver + char[] bokstaver = this.word.toUpperCase().toCharArray(); + + //Beregner poeng basert på bokstav + int sum = 0; + for (int i = 0; i < bokstaver.length; i++) { + sum += map.get(bokstaver[i]); + } + + return sum; } } From 4870f8368de5acc206dfa9a1db29cbaf2e637cad Mon Sep 17 00:00:00 2001 From: Richard Persson Date: Sun, 10 Aug 2025 22:05:02 +0200 Subject: [PATCH 2/2] completed extension --- src/main/java/com/booleanuk/Scrabble.java | 74 ++++++++++++++++++----- 1 file changed, 60 insertions(+), 14 deletions(-) diff --git a/src/main/java/com/booleanuk/Scrabble.java b/src/main/java/com/booleanuk/Scrabble.java index 30e2a3c..e6cfb31 100644 --- a/src/main/java/com/booleanuk/Scrabble.java +++ b/src/main/java/com/booleanuk/Scrabble.java @@ -1,11 +1,10 @@ package com.booleanuk; -import com.sun.source.tree.ArrayTypeTree; import java.util.*; public class Scrabble { - private String word; + private final String word; public Scrabble(String word) { this.word = word; @@ -17,14 +16,15 @@ public int score() { return 0; //Tildeler poeng til vær bokstav - ArrayList group1 = new ArrayList<>(List.of('A','E','I','U','O','U','L','N','R','S','T')); - ArrayList group2 = new ArrayList<>(List.of('D', 'G')); - ArrayList group3 = new ArrayList<>(List.of('B', 'C', 'M', 'P')); - ArrayList group4 = new ArrayList<>(List.of('F', 'H', 'V', 'W', 'Y')); - ArrayList group5 = new ArrayList<>(List.of('K')); - ArrayList group8 = new ArrayList<>(List.of('J', 'X')); - ArrayList group10 = new ArrayList<>(List.of('Q', 'Z')); - ArrayList group11 = new ArrayList<>(List.of('{', '}','[',']')); + List group1 =List.of('A','E','I','U','O','U','L','N','R','S','T'); + Listgroup2 = List.of('D', 'G'); + List group3 =List.of('B', 'C', 'M', 'P'); + List group4 =List.of('F', 'H', 'V', 'W', 'Y'); + List group5 = List.of('K'); + List group8 = List.of('J', 'X'); + List group10 =List.of('Q', 'Z'); + List group11 =List.of('{', '}','[',']'); + List group12 =List.of('!','|','#'); HashMap map = new HashMap<>(); group1.forEach(x-> map.put(x,1)); @@ -38,14 +38,60 @@ public int score() { int count = 0; //Deler opp word i bokstaver char[] bokstaver = this.word.toUpperCase().toCharArray(); + HashMap bracketMap = new HashMap<>(); + for (int i = 0; i