Can someone help me with java homework?

Hey, back again with more java homework. I have no idea how to do this one. It is a scrabble program. The point of the program is to have someone input a word, and the program outputs the score of the program as if it were a word in a scrabble game. And i cant use any if or switch statements. I can probably write it if someone can give me a template on how to do it or give me an idea on how to write it. Thanks for any help.

3 Answers

Relevance
  • warsql
    Lv 4
    1 decade ago
    Favorite Answer

    I would create an int array for the value of each letter. Then you can pull the value by subtracting 'A' from each character and using that as the index into your array. Use a for loop on the chars of the uppercase form of the word.

    If you have to account for double and triple word / letters, then that would be a trick.

  • 1 decade ago

    No if statements is pretty harsh, I would advise using the functions in the String class to get each letter as a char, if you cast a char to an int you get the ascii code(http://www.asciitable.com) now if you make an int array and fill it with the scores of the letters in alphabetical order, you then use the ascii code of the letter as the array index (you will have to subtract the ascii value of 'a' from each one so you will start with 0 index) you can then make a loop to go through the letters in the String and total up the values.

  • 1 decade ago

    the way I would tackle this would be nested loops, also using methods quite a bit. could you use error handling (try/catch) as a work around?

Still have questions? Get your answers by asking now.