#17 Dice_mexiliang

Open
mexiliang wants to merge 2 commits from mexiliang/ZCW-DiceyLab:master into master
24 changed files with 382 additions and 0 deletions
  1. BIN
      .DS_Store
  2. BIN
      Bin.class
  3. 12
    0
      Bin.ctxt
  4. 43
    0
      Bin.java
  5. BIN
      BinTest.class
  6. 13
    0
      BinTest.ctxt
  7. 42
    0
      BinTest.java
  8. BIN
      Dice.class
  9. 8
    0
      Dice.ctxt
  10. 27
    0
      Dice.java
  11. BIN
      DiceTest.class
  12. 13
    0
      DiceTest.ctxt
  13. 42
    0
      DiceTest.java
  14. 12
    0
      README.TXT
  15. BIN
      Simulation.class
  16. 9
    0
      Simulation.ctxt
  17. 30
    0
      Simulation.java
  18. BIN
      StimulationTest.class
  19. 13
    0
      StimulationTest.ctxt
  20. 42
    0
      StimulationTest.java
  21. 76
    0
      package.bluej
  22. BIN
      src/.DS_Store
  23. BIN
      src/main/.DS_Store
  24. BIN
      src/main/java/.DS_Store

BIN
.DS_Store View File


BIN
Bin.class View File


+ 12
- 0
Bin.ctxt View File

@@ -0,0 +1,12 @@
1
+#BlueJ class context
2
+comment0.target=Bin
3
+comment0.text=\n\ Write\ a\ description\ of\ class\ Bin\ here.\n\n\ @Mexi\ Liang\n\ \n
4
+comment1.params=
5
+comment1.target=Bin()
6
+comment2.params=
7
+comment2.target=java.util.Map\ getBinny()
8
+comment3.params=key
9
+comment3.target=java.lang.Integer\ getBinValue(java.lang.Integer)
10
+comment4.params=roll
11
+comment4.target=void\ setBin(java.lang.Integer)
12
+numComments=5

+ 43
- 0
Bin.java View File

@@ -0,0 +1,43 @@
1
+import java.util.TreeMap;
2
+import java.util.*;
3
+
4
+/**
5
+ * Write a description of class Bin here.
6
+ *
7
+ * @Mexi Liang
8
+ * 
9
+ */
10
+public class Bin
11
+{
12
+    Map <Integer,Integer> binny = new TreeMap<>();
13
+    public Bin(){ 
14
+        binny.put(2,0);
15
+        binny.put(3,0);
16
+        binny.put(4,0);
17
+        binny.put(5,0);
18
+        binny.put(6,0);
19
+        binny.put(7,0);
20
+        binny.put(8,0);
21
+        binny.put(9,0);
22
+        binny.put(10,0);
23
+        binny.put(11,0);
24
+        binny.put(12,0);
25
+        
26
+    }
27
+    public Map getBinny(){
28
+    
29
+        return binny;
30
+    
31
+    }
32
+    
33
+    public Integer getBinValue(Integer key){
34
+        
35
+        return binny.get(key);
36
+    }
37
+    public void setBin(Integer roll){
38
+        Integer currentCount = getBinValue(roll); //reuse getBinValue
39
+        currentCount = currentCount +1; //increment 1 of previous value
40
+        binny.put(roll,currentCount); // update new bin value
41
+    }
42
+    
43
+}

BIN
BinTest.class View File


+ 13
- 0
BinTest.ctxt View File

@@ -0,0 +1,13 @@
1
+#BlueJ class context
2
+comment0.target=BinTest
3
+comment0.text=\n\ The\ test\ class\ BinTest.\n\n\ @author\ \ (your\ name)\n\ @version\ (a\ version\ number\ or\ a\ date)\n
4
+comment1.params=
5
+comment1.target=BinTest()
6
+comment1.text=\n\ Default\ constructor\ for\ test\ class\ BinTest\n
7
+comment2.params=
8
+comment2.target=void\ setUp()
9
+comment2.text=\n\ Sets\ up\ the\ test\ fixture.\n\n\ Called\ before\ every\ test\ case\ method.\n
10
+comment3.params=
11
+comment3.target=void\ tearDown()
12
+comment3.text=\n\ Tears\ down\ the\ test\ fixture.\n\n\ Called\ after\ every\ test\ case\ method.\n
13
+numComments=4

+ 42
- 0
BinTest.java View File

@@ -0,0 +1,42 @@
1
+
2
+
3
+import static org.junit.Assert.*;
4
+import org.junit.After;
5
+import org.junit.Before;
6
+import org.junit.Test;
7
+
8
+/**
9
+ * The test class BinTest.
10
+ *
11
+ * @author  (your name)
12
+ * @version (a version number or a date)
13
+ */
14
+public class BinTest
15
+{
16
+    /**
17
+     * Default constructor for test class BinTest
18
+     */
19
+    public BinTest()
20
+    {
21
+    }
22
+
23
+    /**
24
+     * Sets up the test fixture.
25
+     *
26
+     * Called before every test case method.
27
+     */
28
+    @Before
29
+    public void setUp()
30
+    {
31
+    }
32
+
33
+    /**
34
+     * Tears down the test fixture.
35
+     *
36
+     * Called after every test case method.
37
+     */
38
+    @After
39
+    public void tearDown()
40
+    {
41
+    }
42
+}

BIN
Dice.class View File


+ 8
- 0
Dice.ctxt View File

@@ -0,0 +1,8 @@
1
+#BlueJ class context
2
+comment0.target=Dice
3
+comment0.text=\n\ Write\ a\ description\ of\ class\ Dice\ here.\n\n\ @Mexi\ Liang\n\ 06/08/2018\n
4
+comment1.params=n
5
+comment1.target=Dice(java.lang.Integer)
6
+comment2.params=
7
+comment2.target=java.lang.Integer\ tossAndSum()
8
+numComments=3

+ 27
- 0
Dice.java View File

@@ -0,0 +1,27 @@
1
+import java.math.*;
2
+import java.util.Map;
3
+
4
+/**
5
+ * Write a description of class Dice here.
6
+ *
7
+ * @Mexi Liang
8
+ * 06/08/2018
9
+ */
10
+public class Dice
11
+{
12
+    int numOfDice; 
13
+
14
+    public Dice(Integer n){
15
+        numOfDice =n; 
16
+    }
17
+
18
+    public Integer tossAndSum(){
19
+        int sum =0;
20
+        for (int i=1;i<=numOfDice;i++){
21
+            sum = sum + (int)(Math.random()*6+1);    
22
+
23
+        }
24
+        return sum;
25
+    }
26
+
27
+}

BIN
DiceTest.class View File


+ 13
- 0
DiceTest.ctxt View File

@@ -0,0 +1,13 @@
1
+#BlueJ class context
2
+comment0.target=DiceTest
3
+comment0.text=\n\ The\ test\ class\ DiceTest.\n\n\ @author\ \ (your\ name)\n\ @version\ (a\ version\ number\ or\ a\ date)\n
4
+comment1.params=
5
+comment1.target=DiceTest()
6
+comment1.text=\n\ Default\ constructor\ for\ test\ class\ DiceTest\n
7
+comment2.params=
8
+comment2.target=void\ setUp()
9
+comment2.text=\n\ Sets\ up\ the\ test\ fixture.\n\n\ Called\ before\ every\ test\ case\ method.\n
10
+comment3.params=
11
+comment3.target=void\ tearDown()
12
+comment3.text=\n\ Tears\ down\ the\ test\ fixture.\n\n\ Called\ after\ every\ test\ case\ method.\n
13
+numComments=4

+ 42
- 0
DiceTest.java View File

@@ -0,0 +1,42 @@
1
+
2
+
3
+import static org.junit.Assert.*;
4
+import org.junit.After;
5
+import org.junit.Before;
6
+import org.junit.Test;
7
+
8
+/**
9
+ * The test class DiceTest.
10
+ *
11
+ * @author  (your name)
12
+ * @version (a version number or a date)
13
+ */
14
+public class DiceTest
15
+{
16
+    /**
17
+     * Default constructor for test class DiceTest
18
+     */
19
+    public DiceTest()
20
+    {
21
+    }
22
+
23
+    /**
24
+     * Sets up the test fixture.
25
+     *
26
+     * Called before every test case method.
27
+     */
28
+    @Before
29
+    public void setUp()
30
+    {
31
+    }
32
+
33
+    /**
34
+     * Tears down the test fixture.
35
+     *
36
+     * Called after every test case method.
37
+     */
38
+    @After
39
+    public void tearDown()
40
+    {
41
+    }
42
+}

+ 12
- 0
README.TXT View File

@@ -0,0 +1,12 @@
1
+------------------------------------------------------------------------
2
+This is the project README file. Here, you should describe your project.
3
+Tell the reader (someone who does not know anything about this project)
4
+all he/she needs to know. The comments should usually include at least:
5
+------------------------------------------------------------------------
6
+
7
+PROJECT TITLE:
8
+PURPOSE OF PROJECT:
9
+VERSION or DATE:
10
+HOW TO START THIS PROJECT:
11
+AUTHORS:
12
+USER INSTRUCTIONS:

BIN
Simulation.class View File


+ 9
- 0
Simulation.ctxt View File

@@ -0,0 +1,9 @@
1
+#BlueJ class context
2
+comment0.target=Simulation
3
+comment1.params=numOfDice\ toss
4
+comment1.target=Simulation(java.lang.Integer,\ java.lang.Integer)
5
+comment2.params=
6
+comment2.target=void\ runSimulation()
7
+comment3.params=binny
8
+comment3.target=void\ printResults(Bin)
9
+numComments=4

+ 30
- 0
Simulation.java View File

@@ -0,0 +1,30 @@
1
+
2
+public class Simulation
3
+{
4
+    int numOfDice;
5
+    int toss; //number of toss I want to toss
6
+    public Simulation(Integer numOfDice,Integer toss){
7
+        this.numOfDice = numOfDice;
8
+        this.toss = toss;
9
+
10
+    } 
11
+
12
+    public void runSimulation(){
13
+        Bin binny = new Bin();
14
+        Dice dice = new Dice(numOfDice);//need to know how many dice to roll
15
+        for (int i=1;i<=toss;i++){
16
+
17
+            binny.setBin(dice.tossAndSum());// put the toss value in the bin
18
+        }
19
+        printResults(binny);
20
+    }
21
+
22
+    public void printResults(Bin binny){
23
+        for(int i=2;i<=12;i++){
24
+
25
+            System.out.println("SumOfToss " + i + " NumofResult " + binny.getBinValue(i));
26
+        }
27
+
28
+    }
29
+}
30
+

BIN
StimulationTest.class View File


+ 13
- 0
StimulationTest.ctxt View File

@@ -0,0 +1,13 @@
1
+#BlueJ class context
2
+comment0.target=StimulationTest
3
+comment0.text=\n\ The\ test\ class\ StimulationTest.\n\n\ @author\ \ (your\ name)\n\ @version\ (a\ version\ number\ or\ a\ date)\n
4
+comment1.params=
5
+comment1.target=StimulationTest()
6
+comment1.text=\n\ Default\ constructor\ for\ test\ class\ StimulationTest\n
7
+comment2.params=
8
+comment2.target=void\ setUp()
9
+comment2.text=\n\ Sets\ up\ the\ test\ fixture.\n\n\ Called\ before\ every\ test\ case\ method.\n
10
+comment3.params=
11
+comment3.target=void\ tearDown()
12
+comment3.text=\n\ Tears\ down\ the\ test\ fixture.\n\n\ Called\ after\ every\ test\ case\ method.\n
13
+numComments=4

+ 42
- 0
StimulationTest.java View File

@@ -0,0 +1,42 @@
1
+
2
+
3
+import static org.junit.Assert.*;
4
+import org.junit.After;
5
+import org.junit.Before;
6
+import org.junit.Test;
7
+
8
+/**
9
+ * The test class StimulationTest.
10
+ *
11
+ * @author  (your name)
12
+ * @version (a version number or a date)
13
+ */
14
+public class StimulationTest
15
+{
16
+    /**
17
+     * Default constructor for test class StimulationTest
18
+     */
19
+    public StimulationTest()
20
+    {
21
+    }
22
+
23
+    /**
24
+     * Sets up the test fixture.
25
+     *
26
+     * Called before every test case method.
27
+     */
28
+    @Before
29
+    public void setUp()
30
+    {
31
+    }
32
+
33
+    /**
34
+     * Tears down the test fixture.
35
+     *
36
+     * Called after every test case method.
37
+     */
38
+    @After
39
+    public void tearDown()
40
+    {
41
+    }
42
+}

+ 76
- 0
package.bluej View File

@@ -0,0 +1,76 @@
1
+#BlueJ package file
2
+dependency1.from=Simulation
3
+dependency1.to=Bin
4
+dependency1.type=UsesDependency
5
+dependency2.from=Simulation
6
+dependency2.to=Dice
7
+dependency2.type=UsesDependency
8
+editor.fx.0.height=709
9
+editor.fx.0.width=781
10
+editor.fx.0.x=313
11
+editor.fx.0.y=64
12
+objectbench.height=164
13
+objectbench.width=776
14
+package.divider.horizontal=0.6
15
+package.divider.vertical=0.6845018450184502
16
+package.editor.height=364
17
+package.editor.width=674
18
+package.editor.x=178
19
+package.editor.y=51
20
+package.frame.height=600
21
+package.frame.width=800
22
+package.numDependencies=2
23
+package.numTargets=6
24
+package.showExtends=true
25
+package.showUses=true
26
+project.charset=UTF-8
27
+readme.height=58
28
+readme.name=@README
29
+readme.width=47
30
+readme.x=10
31
+readme.y=10
32
+target1.height=50
33
+target1.name=StimulationTest
34
+target1.showInterface=false
35
+target1.type=UnitTestTargetJunit4
36
+target1.width=90
37
+target1.x=440
38
+target1.y=100
39
+target2.height=50
40
+target2.name=BinTest
41
+target2.showInterface=false
42
+target2.type=UnitTestTargetJunit4
43
+target2.width=80
44
+target2.x=280
45
+target2.y=100
46
+target3.association=StimulationTest
47
+target3.height=50
48
+target3.name=Simulation
49
+target3.showInterface=false
50
+target3.type=ClassTarget
51
+target3.width=90
52
+target3.x=410
53
+target3.y=130
54
+target4.association=BinTest
55
+target4.height=50
56
+target4.name=Bin
57
+target4.showInterface=false
58
+target4.type=ClassTarget
59
+target4.width=80
60
+target4.x=250
61
+target4.y=130
62
+target5.association=DiceTest
63
+target5.height=50
64
+target5.name=Dice
65
+target5.showInterface=false
66
+target5.type=ClassTarget
67
+target5.width=80
68
+target5.x=90
69
+target5.y=130
70
+target6.height=50
71
+target6.name=DiceTest
72
+target6.showInterface=false
73
+target6.type=UnitTestTargetJunit4
74
+target6.width=80
75
+target6.x=120
76
+target6.y=100

BIN
src/.DS_Store View File


BIN
src/main/.DS_Store View File


BIN
src/main/java/.DS_Store View File