Directions: Use your own paper for answers. When you are done you may keep this exam sheet and should pick up an answer sheet.
// NumTest.java: Used for question 1 on Exam 2
public class NumTest {
public static void main (String[] args) {
// Exam 2 part 1.a.
// Exam 2 part 1.b.
// Exam 2 part 1.c.
// Exam 2 part 1.d.
}
}
Specifically, fill in the portions of the following java program by answering the questions below:
// 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.a. here
// create an array of four counters
// Answer to Question 4.b. here
// play Chuck-a-Luck RUNS many times
for (int i = 0; i < RUNS; i++) {
// roll the three dice
// Answer to Question 4.c. here
// determine how many fours
// Answer to Question 4.d. here
// record the results in the array counters
// Answer to Question 4.e. here
}
// Total amount of money won or lost.
// 0 fours loses a dollar, 1 four wins a dollar
// 2 fours wins 2 dollars, and 3 fours 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");
}
}