ScrabbleTest.java Questions

Instructions

  1. With the left mouse button pressed, drag the mouse across the contents of the program listing that is shown below. This will select the program listing. Then choose Copy from the Edit menu of your web browser to copy the program listing to the clipboard.
  2. Start your text editor and create a new file called ScrabbleTest.java. Choose Paste to paste the contents of the program listing from the clipboard into the new file.
  3. Save the file to disk and begin answering the questions that are shown below.
  4. When you need to look at the model answer, click here.
  5. Click here to go back to the tutorials menu.

Program listing

// STRING MANIPULATION TUTORIAL
// Copyright (C) 1998-2016 Davin Pearson
// Website: http://davin.50webs.com/java-tutorials

class ScrabbleTest
{
   public static void main(String[] args) {
   }
}

// QUESTIONS:

//  Write the following methods in the ScrabbleTest class:

//  (1) A method public int countVowels(String word)
//  that counts the number of vowels in "word" and returns
//  the result.
// 
//  (2) A similar method countConsonants that returns the
//  number of consonants in a word.
// 
//  (3) Add some code to the main method to test out
//  the first two methods.  Then run the class to
//  see if it works as it should.
// 
//  (4) A method public int scoreWord(String word) that
//  returns the "scrabble score" of the argument "word"
//  according to the following scheme:

//  Vowels score 1 point each while all other letters score
//  10 points each.
// 
//  (5) Add some code to the main method to test out the
//  scoreWord method.  Run the class.
//