#13 rcchung

Açık
rcchung master içindeki rcchung/ZCW-DiceyLab:master işlemelerini 1 ile birleştirmek istiyor
19 değiştirilmiş dosya ile 295 ekleme ve 0 silme
  1. BIN
      .DS_Store
  2. BIN
      Bins.class
  3. 11
    0
      Bins.ctxt
  4. 32
    0
      Bins.java
  5. BIN
      BinsTest.class
  6. 7
    0
      BinsTest.ctxt
  7. 24
    0
      BinsTest.java
  8. BIN
      Dice.class
  9. 9
    0
      Dice.ctxt
  10. 21
    0
      Dice.java
  11. BIN
      DiceTest.class
  12. 7
    0
      DiceTest.ctxt
  13. 27
    0
      DiceTest.java
  14. 12
    0
      README.TXT
  15. 14
    0
      RachelleResults.md
  16. BIN
      Simulation.class
  17. 13
    0
      Simulation.ctxt
  18. 44
    0
      Simulation.java
  19. 74
    0
      package.bluej

BIN
.DS_Store Dosyayı Görüntüle


BIN
Bins.class Dosyayı Görüntüle


+ 11
- 0
Bins.ctxt Dosyayı Görüntüle

@@ -0,0 +1,11 @@
1
+#BlueJ class context
2
+comment0.target=Bins
3
+comment1.params=
4
+comment1.target=Bins()
5
+comment2.params=
6
+comment2.target=java.lang.Integer\ getTens()
7
+comment3.params=result
8
+comment3.target=void\ increment(java.lang.Integer)
9
+comment4.params=n
10
+comment4.target=java.lang.Integer\ getN(java.lang.Integer)
11
+numComments=5

+ 32
- 0
Bins.java Dosyayı Görüntüle

@@ -0,0 +1,32 @@
1
+import java.util.TreeMap;
2
+public class Bins
3
+{
4
+    TreeMap<Integer,Integer> bins = new TreeMap<Integer,Integer>();
5
+    public Bins(){
6
+        bins.put(2,0);
7
+        bins.put(3,0);
8
+        bins.put(4,0);
9
+        bins.put(5,0);
10
+        bins.put(6,0);
11
+        bins.put(7,0);
12
+        bins.put(8,0);
13
+        bins.put(9,0);
14
+        bins.put(10,0);
15
+        bins.put(11,0);
16
+        bins.put(12,0);
17
+    }
18
+
19
+    public Integer getTens(){
20
+        return bins.get(10);
21
+    }
22
+
23
+    public void increment(Integer result){
24
+        Integer prevValue = bins.get(result);
25
+        bins.put(result, prevValue+1);
26
+    }
27
+    
28
+    public Integer getN(Integer n){
29
+        return bins.get(n);
30
+    }
31
+    
32
+}

BIN
BinsTest.class Dosyayı Görüntüle


+ 7
- 0
BinsTest.ctxt Dosyayı Görüntüle

@@ -0,0 +1,7 @@
1
+#BlueJ class context
2
+comment0.target=BinsTest
3
+comment1.params=
4
+comment1.target=void\ getTensTest()
5
+comment2.params=
6
+comment2.target=void\ incrementTest()
7
+numComments=3

+ 24
- 0
BinsTest.java Dosyayı Görüntüle

@@ -0,0 +1,24 @@
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
+public class BinsTest
9
+{   Bins testBins = new Bins();
10
+    @Test
11
+    public void getTensTest(){
12
+        Integer expected = 0;
13
+        Integer actual = testBins.getTens();
14
+        assertEquals(expected,actual);
15
+    }
16
+    
17
+    @Test
18
+    public void incrementTest(){
19
+        Integer expected = 1;
20
+        testBins.increment(10);
21
+        Integer actual = testBins.getTens();
22
+        assertEquals(expected,actual);
23
+    }
24
+}

BIN
Dice.class Dosyayı Görüntüle


+ 9
- 0
Dice.ctxt Dosyayı Görüntüle

@@ -0,0 +1,9 @@
1
+#BlueJ class context
2
+comment0.target=Dice
3
+comment1.params=
4
+comment1.target=Dice()
5
+comment2.params=numberOfDice
6
+comment2.target=Dice(int)
7
+comment3.params=
8
+comment3.target=int\ tossSum()
9
+numComments=4

+ 21
- 0
Dice.java Dosyayı Görüntüle

@@ -0,0 +1,21 @@
1
+
2
+public class Dice
3
+{
4
+    int numberOfDice;
5
+    public Dice(){
6
+        numberOfDice = 1;
7
+    }
8
+    
9
+    public Dice(int numberOfDice){
10
+        this.numberOfDice = numberOfDice;
11
+    }
12
+    
13
+    public int tossSum(){
14
+        int currentTotal = 0;
15
+        for(int i = 0; i <numberOfDice; i++){
16
+            currentTotal += (int)Math.ceil(Math.random()*6);
17
+        }
18
+        return currentTotal;
19
+    }
20
+    
21
+}

BIN
DiceTest.class Dosyayı Görüntüle


+ 7
- 0
DiceTest.ctxt Dosyayı Görüntüle

@@ -0,0 +1,7 @@
1
+#BlueJ class context
2
+comment0.target=DiceTest
3
+comment1.params=
4
+comment1.target=void\ tossTest1()
5
+comment2.params=
6
+comment2.target=void\ tossTest2()
7
+numComments=3

+ 27
- 0
DiceTest.java Dosyayı Görüntüle

@@ -0,0 +1,27 @@
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
+public class DiceTest
9
+{
10
+    @Test
11
+    public void tossTest1(){
12
+       Dice die = new Dice();
13
+       int min = 1;
14
+       int max = 6;
15
+       int actual = die.tossSum();
16
+       assertTrue(min <= actual && actual <= max);
17
+    }
18
+    
19
+    @Test
20
+    public void tossTest2(){
21
+       Dice die = new Dice(2);
22
+       int min = 2;
23
+       int max = 12;
24
+       int actual = die.tossSum();
25
+       assertTrue(min <= actual && actual <= max);
26
+    }
27
+}

+ 12
- 0
README.TXT Dosyayı Görüntüle

@@ -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:

+ 14
- 0
RachelleResults.md Dosyayı Görüntüle

@@ -0,0 +1,14 @@
1
+***
2
+Simulation of 2 dice tossed for 1000000 times.
3
+***
4
+ 2 :    28029: 0.03 **
5
+ 3 :    55074: 0.06 *****
6
+ 4 :    83028: 0.08 ********
7
+ 5 :   111326: 0.11 ***********
8
+ 6 :   138715: 0.14 *************
9
+ 7 :   166904: 0.17 ****************
10
+ 8 :   138899: 0.14 *************
11
+ 9 :   111363: 0.11 ***********
12
+10 :    83303: 0.08 ********
13
+11 :    55580: 0.06 *****
14
+12 :    27779: 0.03 **

BIN
Simulation.class Dosyayı Görüntüle


+ 13
- 0
Simulation.ctxt Dosyayı Görüntüle

@@ -0,0 +1,13 @@
1
+#BlueJ class context
2
+comment0.target=Simulation
3
+comment1.params=numberOfDice\ numberOfTosses
4
+comment1.target=Simulation(java.lang.Integer,\ java.lang.Integer)
5
+comment2.params=
6
+comment2.target=void\ runSimulation()
7
+comment3.params=numberOfSpecificResult
8
+comment3.target=float\ ratioOfTosses(int)
9
+comment4.params=
10
+comment4.target=void\ printHeader()
11
+comment5.params=results
12
+comment5.target=void\ printResults(Bins)
13
+numComments=6

+ 44
- 0
Simulation.java Dosyayı Görüntüle

@@ -0,0 +1,44 @@
1
+
2
+public class Simulation
3
+{   
4
+    Integer numberOfDice;
5
+    Integer numberOfTosses;
6
+    public Simulation(Integer numberOfDice,Integer numberOfTosses){
7
+        this.numberOfDice = numberOfDice;
8
+        this.numberOfTosses = numberOfTosses;
9
+    }
10
+    Bins results = new Bins();
11
+    public void runSimulation(){
12
+        int currentRoll = 0;
13
+        Dice dice = new Dice(numberOfDice);
14
+        Bins results = new Bins();
15
+        while(currentRoll < numberOfTosses){
16
+            int result = dice.tossSum();
17
+            currentRoll++; 
18
+            results.increment(result);
19
+        }
20
+        printHeader();
21
+        printResults(results);
22
+    }
23
+
24
+    public float ratioOfTosses(int numberOfSpecificResult){
25
+        return numberOfSpecificResult/(float)numberOfTosses;
26
+    }
27
+    
28
+    public void printHeader(){
29
+        System.out.println("***\n" + "Simulation of " + numberOfDice
30
+        + " dice tossed for " + numberOfTosses + " times.\n***");
31
+    }
32
+    
33
+    public void printResults(Bins results){
34
+        for(int i = 2; i <=12;i++){
35
+            float ratio = ratioOfTosses(results.getN(i));
36
+            StringBuilder stars = new StringBuilder();
37
+            for(int j = 1; j < (ratio*100); j++){
38
+                    stars.append("*");
39
+            }
40
+            System.out.println(String.format("%2s :%9s:%5.2f ",i,results.getN(i),ratio)+stars.toString());
41
+        }
42
+    }
43
+
44
+}

+ 74
- 0
package.bluej Dosyayı Görüntüle

@@ -0,0 +1,74 @@
1
+#BlueJ package file
2
+dependency1.from=DiceTest
3
+dependency1.to=Dice
4
+dependency1.type=UsesDependency
5
+dependency2.from=BinsTest
6
+dependency2.to=Bins
7
+dependency2.type=UsesDependency
8
+dependency3.from=Simulation
9
+dependency3.to=Bins
10
+dependency3.type=UsesDependency
11
+dependency4.from=Simulation
12
+dependency4.to=Dice
13
+dependency4.type=UsesDependency
14
+editor.fx.0.height=709
15
+editor.fx.0.width=921
16
+editor.fx.0.x=345
17
+editor.fx.0.y=23
18
+objectbench.height=101
19
+objectbench.width=461
20
+package.divider.horizontal=0.6
21
+package.divider.vertical=0.8115183246073299
22
+package.editor.height=458
23
+package.editor.width=674
24
+package.editor.x=95
25
+package.editor.y=104
26
+package.frame.height=631
27
+package.frame.width=800
28
+package.numDependencies=4
29
+package.numTargets=5
30
+package.showExtends=true
31
+package.showUses=true
32
+project.charset=UTF-8
33
+readme.height=58
34
+readme.name=@README
35
+readme.width=47
36
+readme.x=10
37
+readme.y=10
38
+target1.association=BinsTest
39
+target1.height=50
40
+target1.name=Bins
41
+target1.showInterface=false
42
+target1.type=ClassTarget
43
+target1.width=80
44
+target1.x=200
45
+target1.y=90
46
+target2.height=50
47
+target2.name=BinsTest
48
+target2.showInterface=false
49
+target2.type=UnitTestTargetJunit4
50
+target2.width=80
51
+target2.x=230
52
+target2.y=60
53
+target3.height=50
54
+target3.name=Simulation
55
+target3.showInterface=false
56
+target3.type=ClassTarget
57
+target3.width=90
58
+target3.x=10
59
+target3.y=100
60
+target4.association=DiceTest
61
+target4.height=50
62
+target4.name=Dice
63
+target4.showInterface=false
64
+target4.type=ClassTarget
65
+target4.width=80
66
+target4.x=70
67
+target4.y=40
68
+target5.height=50
69
+target5.name=DiceTest
70
+target5.showInterface=false
71
+target5.type=UnitTestTargetJunit4
72
+target5.width=80
73
+target5.x=100
74
+target5.y=10