Question 2 public static void mainstring args char t

This preview shows 9 out of 14 pages.

Question 2 public static void main(String[ ] args) { char[] t = {'G', 'e', 'e', '-', 'G', 'e', 'e'}; Rec(t, t.length - 1); } The method Rec will start from the end of the array t , change the case of each letter (ignoring non-letter characters), and print it. The result: EEgEEg Irrelevant side remark: Did you see why the class was called “Football ”?
Image of page 9

Subscribe to view the full document.

10 Question 3 [15] Translate the following algorithm to a Java method: GIVENS: Base: (a logarithm base, known to be > 0) Operand: (an array of integers for which to find the integer logarithm) N (the number of values in array Operand) RESULT: IntLog: (an array of N integer logarithms for the values in array Operand; a value of -1 is returned if the logarithm does not exist) INTERMEDIATES: Index (array index) Value (used for repeated divisions) Count (counts number of times an operand can be divided by base) HEADER: IntLog Logarithms( Base, Operand, N ) Question 3 BODY: Index < N ? Value Base Value Value / Base Count Count + 1 Value Operand[Index] Count 0 IntLog[Index] Count Operand[Index] > 0 ? IntLog[Index] – 1 Index 0 IntLog CreateNewArray(N) true true true false false false Index Index + 1
Image of page 10
11 Question 3 public static int[] logarithms( int base, int[] operand, int n) { int intlog; // RESULT: An array of logarithms for the values in operand int index; int value; int count; index = 0; intlog = new int[n]; while ( index < n ) { if ( operand[index] > 0 ) { value = operand[index]; count = 0; while ( value >= base ) { value = value / base; count = count + 1; } intlog[index] = count; } else { intlog[index] = -1; } index = index = 1; } return intlog; } Question 4 [15] Olympic 10 metre platform diving events are scored as follows. Each judge watches an athlete's dive, and then submits a score for the dive (out of 10). The dive is also previously assigned a "degree of difficulty" (DD) based on the complexity of the particular dive (example: forward 2 1/2 somersault in the tuck position has DD = 2.7). The highest and lowest scores are discarded, and the remaining scores are added together and then multiplied by the degree of difficulty to determine the total dive score. Write an algorithm that will compute an athlete's total dive score from an array of scores submitted by N judges, for a dive of degree of difficulty DD.
Image of page 11

Subscribe to view the full document.

12 Question 4 GIVENS: Scores (An array of judges’ scores) N (The length of array Scores) DD (Dive’s degree of difficulty) RESULT: Final (The diver’s final score) INTERMEDIATES: Index (Index for array Scores) Sum (Sum of values in array Scores) Max (Maximum score) Min (Minimum score) HEADER: Final DetermineFinalScore( Scores, N, DD ) Question 4 BODY: Index < N Scores[Index] > Max Max Scores[Index] Sum Sum + Scores[Index] Index Index + 1 true Max Scores[0] Min Scores[0] Sum Scores[0] Index 1 true false Final DD × ( Sum – Max – Min ) Scores[Index] < Min Min Scores[Index] false true false
Image of page 12