Progress Checks for Chapter 8 & 9

1. Create a string comparison algorithm.  In the context of DNA, we are looking for a small fragment in a larger string. The user is requested to enter the two strings, then they are compared to find matches.

2. Show the state of memory after the execution of each statement in the following code:

a. String word1, word2;

b. word1= "Hi";

c. word2 = word1;

d. word1= "Bye";

3. Using state-of-memory diagrams, show how the following two groups of statements differ.

A. String word1, word2;

word1="Java";

word2= word1;

B. String word1, word2;

word1= "Java";

word2="Java";

 

4. Write a method that returns the number of uppercase letters in a String object passed to the method as a parameter.

A. Use is UpperCase() method of the Character class (returns true if the passed parameter of type char is an uppercase letter.

B. Do not use isUpperCase() (Note: the ASCII code of any uppercase letter is 65 ('A') to 90 ('Z').

 

5. Write a method that reads a sentence and prints out the sentence with all uppercase letters changed to lowercase and all lowercase letters changed to uppercase.

A. with the character class methods

B. without the character class methods

 

6. Write a method that transposes words in a given sentence.

For example:

input: I love Java

output: I evol avaJ

(Assume no punctuation and the string starts with a character with one space between words.)

 

7. Assume an array floatArray() has been declared of size 365 that stores daily temperatures for one year. Write methods for:

a. the hottest day of the year

b. the coldest day of the year

c. the temperature of any given day. Note: the day is specified by two input values (month 1..12 and day (1..31)) reject invalid input values.

d. The average temperature for each month.

e. The difference between the hottest and coldest days of every month.

 

8. Using hte paysScaleTable in chapter 9.9, write the code to find

a. the average pay for every grade level.

b. the average pay for every step (i.e. average of every column)