Please remember that homework must be handed in on time. No late homework will be accepted.
Review the suggested readings from chapters 5 & 7 of your textbook and answer the following questions based on your textbook and the course lecture material.
A spinner is implemented with a Java class named Spinner with the following API. Note that the methods are NOT static. (What other classes have you used that had non-static methods?)
public void spin()
Spins the spinner to some random value between 1 and 10 on it.public int getSpinValue()
Returns the value currently being pointed to on the spinner.
Complete the Java method below that takes a Spinner object named spin and spins the spinner repeatedly until the number 5 is spun a total of three times. Your method should print out each number that is spun.
public static void spinFive(Spinner spinner) { }
Write a method named makeCaptcha with no parameters that creates and returns a string of characters for a captcha consisting of some random set of 4-8 uppercase letters, lowercase letters and/or digits. Your method should pick a random number between 4 and 8 (inclusive) and then use a loop to build the string one character at a time starting from an empty string. Once the string is built, return the string.
int[] data = { 0, 1, 2, 3, 4, 0, 1, 2, 3, 4, 0, 1, 2, 3, 4 };
What is output on the screen for each of the following code fragments? Trace each loop completely for full credit. (Do not just enter these into Eclipse and write down the answers. If you do, you will not get full credit.)
int sum = 0; for (int i = 0; i < data.length; i += 3) sum += data[i]; System.out.println(sum);
int index = 0; while (index < data.length) { index += 5; System.out.println(data[index]); }
int position = data.length - 1; do { System.out.println(data[position]); position /= 2; } while (position > 0);
int[] data = { 0, 1, 2, 3, 4, 0, 1, 2, 3, 4, 0, 1, 2, 3, 4 }; is the same as: int[] data = new __________________; for (int i = 0; i < data.length; i++) { data[i] = ___________________; }
int[] data = { 1, 2, 4, 7, 11, 16, 22, 29, 37 }; is the same as: int[] data = new __________________; data[0] = 1; for (int i = 1; i < data.length; i++) { data[i] = ___________________; }
public static double findLargest(double[] sample) { }
public static int countBelow(double[] sample, double threshold) { }