You will use the following files: • SingleDie.class //you won\'t directly use th
ID: 3745471 • Letter: Y
Question
You will use the following files:
• SingleDie.class //you won't directly use this class, representing a six-sided die
• CrapsDice.class //has the following public interface:
o public CrapsDice() //constructor (creates and uses 2 SingleDie objects, this is called composition or has-a)
o public int roll() //rolls two SingleDies (six-sided dies) and returns the result
Roll the dice 752 times and report the percentage of times that a 2, 3, or 12 is rolled (one number). You will need to cast to a double to get the correct percentage (or you will be performing integer division). Call your driver class Craps.java and include the following static method:
• public static int playCraps(int num_rolls) //returns the number of times that a 2, 3, or 12 is rolled
CrabsDice.class:
cafe babe 0000 0032 001d 0a00 0800 1407
0015 0a00 0200 1609 0007 0017 0900 0700
180a 0002 0019 0700 1a07 001b 0100 0264
3101 000b 4c53 696e 676c 6544 6965 3b01
0002 6432 0100 063c 696e 6974 3e01 0003
2829 5601 0004 436f 6465 0100 0f4c 696e
654e 756d 6265 7254 6162 6c65 0100 0472
6f6c 6c01 0003 2829 4901 000a 536f 7572
6365 4669 6c65 0100 0e43 7261 7073 4469
6365 2e6a 6176 610c 000c 000d 0100 0953
696e 676c 6544 6965 0c00 0c00 1c0c 0009
000a 0c00 0b00 0a0c 0010 0011 0100 0943
7261 7073 4469 6365 0100 106a 6176 612f
6c61 6e67 2f4f 626a 6563 7401 0004 2849
2956 0021 0007 0008 0000 0002 0002 0009
000a 0000 0002 000b 000a 0000 0002 0001
000c 000d 0001 000e 0000 0043 0004 0001
0000 001f 2ab7 0001 2abb 0002 5910 06b7
0003 b500 042a bb00 0259 1006 b700 03b5
0005 b100 0000 0100 0f00 0000 1200 0400
0000 0800 0400 0900 1100 0a00 1e00 0b00
0100 1000 1100 0100 0e00 0000 2800 0200
0100 0000 102a b400 04b6 0006 2ab4 0005
b600 0660 ac00 0000 0100 0f00 0000 0600
0100 0000 0f00 0100 1200 0000 0200 13
SingleDie.Class:
cafe babe 0000 0032 0020 0a00 0800 1709
0007 0018 0900 0700 190a 0005 001a 0700
1b0a 0005 0017 0700 1c07 001d 0100 0472
616e 6401 0012 4c6a 6176 612f 7574 696c
2f52 616e 646f 6d3b 0100 086e 756d 5369
6465 7301 0001 4901 0006 3c69 6e69 743e
0100 0328 2956 0100 0443 6f64 6501 000f
4c69 6e65 4e75 6d62 6572 5461 626c 6501
0004 2849 2956 0100 0472 6f6c 6c01 0003
2829 4901 0008 3c63 6c69 6e69 743e 0100
0a53 6f75 7263 6546 696c 6501 000e 5369
6e67 6c65 4469 652e 6a61 7661 0c00 0d00
0e0c 000b 000c 0c00 0900 0a0c 001e 001f
0100 106a 6176 612f 7574 696c 2f52 616e
646f 6d01 0009 5369 6e67 6c65 4469 6501
0010 6a61 7661 2f6c 616e 672f 4f62 6a65
6374 0100 076e 6578 7449 6e74 0100 0428
4929 4900 2100 0700 0800 0000 0200 0a00
0900 0a00 0000 0200 0b00 0c00 0000 0400
0100 0d00 0e00 0100 0f00 0000 2b00 0200
0100 0000 0b2a b700 012a 1006 b500 02b1
0000 0001 0010 0000 000e 0003 0000 0009
0004 000a 000a 000b 0001 000d 0011 0001
000f 0000 002a 0002 0002 0000 000a 2ab7
0001 2a1b b500 02b1 0000 0001 0010 0000
000e 0003 0000 000e 0004 000f 0009 0010
0001 0012 0013 0001 000f 0000 002b 0002
0002 0000 000f b200 032a b400 02b6 0004
0460 3c1b ac00 0000 0100 1000 0000 0a00
0200 0000 1400 0d00 1500 0800 1400 0e00
0100 0f00 0000 2300 0200 0000 0000 0bbb
0005 59b7 0006 b300 03b1 0000 0001 0010
0000 0006 0001 0000 0005 0001 0015 0000
0002 0016
Explanation / Answer
Craps.java
public class Craps {
public static int playCraps(int num_rolls){
CrapsDice die = new CrapsDice();
double result;
for(int x = 0; x < num_rolls; x++){
double dieRoll = die.roll();
if(dieRoll == 2 || dieRoll == 3 || dieRoll == 12){
result += dieRoll;
}
}
return result/num_rolls;
};
public static void main(String[] args){
playCraps(752);
System.out.println();
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.