BO(Question 4.2.1:) The following code returns whether or not the current
parameter ch is a vowel. The parameter ch is of type char which is
used to hold the components of a string. That is to say, strings are
built out of sequences of chars. Also note the use of the
TT(Character.toUpperCase) FUNCTION to convert chars into uppercase chars
so that the code works equally well for TT(isVowel('a')) and
TT(isVowel('A')). Study, compile and run the following code. Does it print
what you expected it to? If not, then fix the bug.

@cindex TT(Character.toUpperCase)
@cindex Introducing chars
@cindex chars, introducing

@example
CLASS Scrabble
BEGIN
PD FUNCTION boolean isVowel(char ch)
PD BEGIN
PD PD ch = Character.toUpperCase(ch);
PD PD IF ((ch == 'A') OR (ch == 'E') OR (ch == 'I') OR (ch == 'O') OR (ch == 'U'))
PD PD THEN RETURN TRUE;
PD PD ELSE RETURN FALSE;
PD END
PD BEGINMAIN
PD PD System.out.println(isVowel('a'));
PD ENDMAIN
END
@end example

@cindex The difference between TT(==) and TT(=)

In the above code, note the difference between TT(a = b) example:
TT(ch = Character.toUpperCase(ch)) and TT(a == b) example: TT(ch ==
'A'). The first is an assignment that sets a to be whatever the value
of b is, while the second is a question that says whether or not the
two arguments a and b are equal.

Note that later on in this tutorial you will learn that this is not
the way to compare two strings. Also note the use of the EM(boolean)
return type. This means that the return value is either TRUE or FALSE.

BO(Question 4.2.2:) By copying the pattern established by the above code,
write a FUNCTION TT(isConsonant) which returns whether or not the given
argument is not a vowel. The easiest way to do this is to write
isVowel(ch) == FALSE which means: ``ch is not a vowel''. You will also
need to ensure that the parameter ch is greater than or equal to 'A'
and less than or equal to 'Z'. Then test your code by calling
TT(isConsonant) from the MAIN FUNCTION.

BO(Question 4.2.3:) By copying the pattern established in the following code:

@example
FUNCTION INT countVowels(String word)
BEGIN
PD VAR int result = 0;
PD SUPERFOR (VAR int i=0 TU i<word.length()-1)
PD BEGIN
PD PD VAR char ch = word.charAt(i);
PD PD IF (isVowel(ch)) THEN result = result + 1;
PD END
PD RETURN result;
END
@end example

write a FUNCTION that counts the number of consonants in a word. Note
the use of the VAR keyword for defining variables that are local to
functions. Local variables are very much like parameters that were
introduced in the previous tutorial. In the above code, note the use
of TT(word.charAt(i)) and TT(word.length()). The first of these
results the character at location in the string word given by the
value of i and the second of these returns the length of the string
word. In Tutorial 11 you will learn that these are called methods
which are different from functions that currently know how to
write. Until we get to this tutorial and we are ready to teach you how
to write your own methods, you will only call existing methods such as
the above methods of the String class. Then test your code by calling
it from the MAIN FUNCTION.

@cindex Calling existing methods of the TT(String) class

BO(Question 4.2.4:) Write a FUNCTION TT(simpleScoreWord) that calls
TT(countVowels) and TT(countConsonants) to give a Simple Score of a
word. The Simple Score of a word is the number of vowels in the word
plus the number of consonants in the word times ten. Then test your
code by calling it from the MAIN FUNCTION.

BO(Question 4.2.5:) Write a FUNCTION TT(advancedScoreLetter) that
returns the Advanced Score of a letter. Here is a breakdown of the
distribution of letters for the purpose of the calculation of the
Advanced Scores.

@example
2 blank tiles (scoring 0 points)
1 point: E 12 tiles, A 9 tiles, I 9 tiles, O 8 tiles, N 6 tiles, R 6 tiles, T 6 tiles, L 4 tiles, S 4 tiles, U 4 tiles
2 points: D 4 tiles, G 3 tiles
3 points: B 2 tiles, C 2 tiles, M 2 tiles, P 2 tiles
4 points: F 2 tiles, H 2 tiles, V 2 tiles, W 2 tiles, Y 2 tiles
5 points: K 1 tiles
8 points: J 1 tiles, X 1 tiles
10 points: Q 1 tiles, Z 1 tiles
@end example

Then test your code by calling it from the MAIN FUNCTION.

BO(Question 4.2.6:) Write a FUNCTION TT(advancedScoreWord) that
returns the Advanced Score of a word. The Advanced Score of a word is
the sum of the Advanced Scores of each letter in the word. If the word
is eight letters long then you should add an extra, say, 50 points to
the score. Then test your code by calling it from the MAIN FUNCTION.

BO(Question 4.2.7:) Comparing strings. Amend the TT(advancedScoreWord)
FUNCTION so that swear words get a score of zero. For the purposes of
this question you only need to think of three swear-words to add to
the code. In the interests of not offending anyone, please keep your
choice of swear words very tame. When comparing strings it is a
mistake to use == which you already know is how you compare the
following types that you know of so far: booleans, chars and
ints. Using == on strings compiles and runs but gives you the
incorrect result. The correct method to compare strings is to use the
equals method of the string class like so: TT(word.equals("bugger"))
which returns TRUE or FALSE, depending on whether or not the string
word currently holds the value "bugger".

BO(Question 4.2.8:) Change the TT(advancedScoreWord) FUNCTION so it works
equally well with uppercase words and lowercase words. You will need
write to call either TT(word.toUpperCase()) or TT(word.toLowerCase())
and store the result in word.

@cindex TT(toUpperCase()) of the TT(String) class
@cindex TT(toLowerCase()) of the TT(String) class

