I am working on a scrabble assignment. We have to assign values to each word and then put them in order of point value. We will read the words from a text file. So I'm thinking to create an ArrayList to store each word. My question is, how do I read each character and assign a value to it? I believe I will use a for loop. I'm just confused when I start working with char... I think that's what this will be.
Once I figure out how to give a score to each word, do I then use the comparator interface to sort them?
EDIT: I realized maybe I didn't make this clear. Each letter is given a value from the Scrabble game. So I have to read each letter of each word and assign a value that will add up to a total score for the word. Like the word QUIT would be 10 + 1 + 1 + 1 = 13.
What you could do is to add all words as keys in a hash table, initiating them all with a value of 0. Then you loop through the keys and use a for loop to check the value of each character of each word, adding the word’s sum value as the value for that word’s key in the hash table.
The for loop for each word would look something like this:
int sumValue = 0;
for(int i =0; i < word.length(); i++)}
sumValue += value(word.charAt(i))
}
The return value() is just my way to represent that you return the value of the specific character you are at. Of course this depends on which character it is. Maybe it would be wise to keep another hash table with each character associated with a scrabble value that you access in the loop (like A:1, X:8 etc).