lab0ans - // Precondition: letter is a valid scrabble...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
import java.util.*; public class ScrabbleScorer { public static void main(String[] args) { Scanner scan = new Scanner(System.in); System.out.println("Input a valid Scrabble word: "); String word = scan.nextLine(); // assume word is ok for now int score = 0; for (int i = 0; i < word.length(); i++) score += computeValue(word.charAt(i)); System.out.println("WORD: " + word + " WORD SCORE: " + score); } public static int computeValue(char letter) {
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: // Precondition: letter is a valid scrabble letter // (in lowercase) or * for a blank // Returns the scrabble value of the letter or 0 if * String alphabet = &quot;abcdefghijklmnopqrstuvwxyz&quot;; int values = {1, 3, 3, 2, 1, 4, 2, 4, 1, 8, 5, 1, 3, 1, 1, 3, 10, 1, 1, 1, 1, 4, 4, 8, 4, 10}; if (letter == '*') return 0; return values[alphabet.indexOf(letter)]; // OR return values[letter-'a']; } }...
View Full Document

This note was uploaded on 12/19/2009 for the course CS 121 taught by Professor Reid-miller during the Spring '09 term at Carnegie Mellon.

Ask a homework question - tutors are online