Directions: Write your answers in the spaces below. Use extra paper if you need to. Do not spend too much time on any one problem.
// ScoresTest.java: Used for question 1 on Exam 2
public class ScoresTest {
public static void main (String[] args) {
final int SIZE = 50;
// Exam 2 part 1.a.
int numScores = 0;
// Exam 2 part 1.b.
int sumScores = 0;
// Exam 2 part 1.c.
double averageScore;
// Exam 2 part 1.d.
}
}
public int linearSearch(int[] a, int value)
// Exam 2 part 2.a.
public boolean noZeros(int[] a)
// Exam 2 part 2.b.
// Dice.java: use Random to roll one die
import java.util.*;
public class Dice {
private static Random ran = new Random();
public int roll() {
// Answer to Question 4.a. here
}
}
// ChuckaLuck.java: play the game Chuck-a-Luck
public class ChuckaLuck {
public static final int RUNS = 1000;
public static void main (String[] args) {
// create an instance of the Dice class
// Answer to Question 4.b. here
// create an array of four counters
// Answer to Question 4.c. here
// play Chuck-a-Luck RUNS many times
for (int i = 0; i < RUNS; i++) {
// roll the three dice
// Answer to Question 4.d. here
// determine how many fives
// Answer to Question 4.e. here
// record the results in the array counters
// Answer to Question 4.f. here
}
// Total amount of money won or lost.
// 0 fives loses a dollar, 1 five wins a dollar
// 2 fives wins 2 dollars, and 3 fives wins 3 dollars
int totalMoney; // total money won or lost
totalMoney = counter[0]*(-1) + counter[1]*1 +
counter[2]*2 + counter[3]*3;
System.out.print("Total Money (won/lost): $" + Math.abs(totalMoney));
if (totalMoney < 0) System.out.println(" lost");
else System.out.println(" won");
}
}