some code samples, various examples of simple modeling ideas and some minor algorithms.

Scrabble.java 963B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. import java.io.*;
  2. class Scrabble
  3. {
  4. // A class to give you the scrabble score of a word
  5. public static void main(String[] args) throws IOException
  6. {
  7. BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
  8. System.out.print("Enter a word: ");
  9. String word=in.readLine();
  10. System.out.println("Scrabble score is: "+score(word));
  11. }
  12. public static int score(String word)
  13. {
  14. String uword=word.toUpperCase();
  15. int score=0;
  16. for(int i=0;i<uword.length();i++)
  17. switch(uword.charAt(i))
  18. {
  19. case 'Q': case 'Z':
  20. score+=10; break;
  21. case 'J': case 'X':
  22. score+=8; break;
  23. case 'K':
  24. score+=5; break;
  25. case 'F': case 'H': case 'V': case 'W': case 'Y':
  26. score+=4; break;
  27. case 'B': case 'C': case 'M': case 'P':
  28. score+=3; break;
  29. case 'D': case 'G':
  30. score+=2;break;
  31. default:
  32. score+=1;break;
  33. }
  34. return score;
  35. }
  36. }