PRACTICE FINAL E -- SPRING 2003 There will probably not be time to do all problems. You choose the problems you want to work. 1. Construct the variable trace and predict the output. Recall that System.exit(0); means terminate the program. public static void main(String[] args) { int[] x = {12, 19, 34, 41, 57, 65, 79, 91, 99}; int a = 0, b = 8, c, y = 79; while (a < b) { if (x[a] == y) { System.out.println("Index is " + a); System.exit(0); } if (x[b] == y) { System.out.println("Index is " + b); System.exit(0); } c = (a + b) / 2; if (x[c] <= y) a = c; else b = c; } System.out.println("Index for y not found."); } Use a variable table like this: x[0] x[1] x[2] x[3] x[4] x[5] x[6] x[7] x[8] a b c y +----+----+----+----+----+----+----+----+----+----+----+----+----+ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Page 2 2. Design, code, and test a class containing information about a hospital patient. Include three or four instance variables. Also include a parameterized constructor, accessor methods for each instance variable, and a toString method. (a) Draw the UML diagram. (b) Write the code for the class. (c) Write a main method to test your class. (d) Predict the output of the main method in (d). 3. A main method contains an array of Kid objects, with private instance variables name, gender, and age. Write a for loop that counts how many of the objects have the name Emily. Then output the count. 4. Write a static method that inputs a String and returns the string with the vowels removed. For example String s = "orange", t; t = removeVowels(s); // t is now the string "rng". 5. Write an applet with two textfields and a button. The user enters a string in the first textfield. When the button is pressed, the application removes the vowels from the string and puts the resulting string in the second textfield. Use the removeVowels method from Problem 4.