CS 1401, Quiz 7a

Date: Thursday, March 8, 2007
Section (9 am or 10:30 am): ____________________________
Name (please type legibly, ideally in block letters): ______________________________________________________________________

Important: this extra quiz is formed from problems presented in Test 2; grades for this extra quiz will partly compensate for missing grades on Test 2.

2. To promote the census, the census organizers decided to send to each citizen a nice leaflet in which this citizen's data is listed first, and his neighbor's data is listed second. Write down a code that, given two strings s1 and s2 and the name of the citizen (stored in the string name), finds the string which contains this name and places it first. Assume that the names are always spelled in a normal way: first letter capitalized, all other letters small.

Example: if s1 is "Xiaojing Wang", s2 is "Carlos Acosta", and name is "Acosta", then after your code, s1 should contain "Carlos Acosta" and s2 should contain "Xiaojing Wang".

Trace your code, step by step, on this example: draw all the boxes and show how their values change after each operation.

For extra credit: make the code work also if the name is spelled in all caps.
































4. Suppose that the results of the census are stored in the file census.dat. Use the while loop to find and print the line that contains your name. Trace your code on the example of a file in which the first line is "Carlos Acosta" and the second is the line about you.

Reminder: to create an object for reading from a file, you need to use the following code:

Scanner fromFile = new Scanner(new FileReader("census.dat"));