Arin Turpin 8 lat temu
rodzic
commit
86ea950993
12 zmienionych plików z 256 dodań i 0 usunięć
  1. BIN
      .DS_Store
  2. BIN
      Bin.class
  3. 10
    0
      Bin.ctxt
  4. 41
    0
      Bin.java
  5. BIN
      Dice.class
  6. 6
    0
      Dice.ctxt
  7. 26
    0
      Dice.java
  8. 12
    0
      README.TXT
  9. BIN
      Simulation.class
  10. 14
    0
      Simulation.ctxt
  11. 95
    0
      Simulation.java
  12. 52
    0
      package.bluej

BIN
.DS_Store Wyświetl plik


BIN
Bin.class Wyświetl plik


+ 10
- 0
Bin.ctxt Wyświetl plik

@@ -0,0 +1,10 @@
1
+#BlueJ class context
2
+comment0.target=Bin
3
+comment0.text=\n\ Write\ a\ description\ of\ class\ Bin\ here.\n\n\ @author\ (your\ name)\n\ @version\ (a\ version\ number\ or\ a\ date)\n
4
+comment1.params=
5
+comment1.target=Bin()
6
+comment2.params=key
7
+comment2.target=void\ counter(java.lang.Integer)
8
+comment3.params=key
9
+comment3.target=java.lang.Integer\ getValue(int)
10
+numComments=4

+ 41
- 0
Bin.java Wyświetl plik

@@ -0,0 +1,41 @@
1
+import java.util.*;
2
+/**
3
+* Write a description of class Bin here.
4
+*
5
+* @author (your name)
6
+* @version (a version number or a date)
7
+*/
8
+public class Bin
9
+{
10
+
11
+
12
+   private Map<Integer, Integer> entries = new TreeMap();
13
+   
14
+   public Bin(){
15
+   entries.put(2,0);
16
+   entries.put(3,0);
17
+   entries.put(4,0);
18
+   entries.put(5,0);
19
+   entries.put(6,0);
20
+   entries.put(7,0);
21
+   entries.put(8,0);
22
+   entries.put(9,0);
23
+   entries.put(10,0);
24
+   entries.put(11,0);
25
+   entries.put(12,0);
26
+   
27
+   }
28
+   
29
+   
30
+   public void counter(Integer key){
31
+       Integer count = entries.get(key);
32
+       entries.put(key, count +1);
33
+   
34
+   }
35
+   
36
+   public Integer getValue(int key){
37
+   return entries.get(key);
38
+   }
39
+
40
+   
41
+}

BIN
Dice.class Wyświetl plik


+ 6
- 0
Dice.ctxt Wyświetl plik

@@ -0,0 +1,6 @@
1
+#BlueJ class context
2
+comment0.target=Dice
3
+comment0.text=\n\ Write\ a\ description\ of\ class\ Dice\ here.\n\n\ @author\ (your\ name)\n\ @version\ (a\ version\ number\ or\ a\ date)\n
4
+comment1.params=numDiceRolled
5
+comment1.target=int\ roll(int)
6
+numComments=2

+ 26
- 0
Dice.java Wyświetl plik

@@ -0,0 +1,26 @@
1
+import java.math.*;
2
+/**
3
+* Write a description of class Dice here.
4
+*
5
+* @author (your name)
6
+* @version (a version number or a date)
7
+*/
8
+public class Dice
9
+{
10
+   
11
+   public static int roll(int numDiceRolled){
12
+
13
+       int totalNumber = 0;
14
+       
15
+       for (int x = 1; x <= numDiceRolled; x++){
16
+           int Roll = (int)(6.0 * Math.random()) +1;
17
+           
18
+           totalNumber += Roll;
19
+           
20
+       }
21
+
22
+       return totalNumber;
23
+   }
24
+
25
+
26
+}

+ 12
- 0
README.TXT Wyświetl plik

@@ -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 Wyświetl plik


+ 14
- 0
Simulation.ctxt Wyświetl plik

@@ -0,0 +1,14 @@
1
+#BlueJ class context
2
+comment0.target=Simulation
3
+comment0.text=\n\ Created\ by\ leon\ on\ 11/6/17.\n
4
+comment1.params=noDice\ diceRoll
5
+comment1.target=Simulation(int,\ int)
6
+comment2.params=args
7
+comment2.target=void\ main(java.lang.String[])
8
+comment3.params=
9
+comment3.target=void\ simMill()
10
+comment4.params=
11
+comment4.target=void\ printer()
12
+comment5.params=
13
+comment5.target=void\ simulation()
14
+numComments=6

+ 95
- 0
Simulation.java Wyświetl plik

@@ -0,0 +1,95 @@
1
+import java.util.*;  
2
+/**
3
+ * Created by leon on 11/6/17.
4
+ */
5
+
6
+public class Simulation{
7
+    private int noDice;
8
+    private int diceRoll;
9
+    Bin bin = new Bin();
10
+    public Simulation(int noDice, int diceRoll){
11
+        this.noDice = noDice;
12
+        this.diceRoll = diceRoll;
13
+
14
+    }
15
+
16
+    public static void main(String[]args){
17
+
18
+    }
19
+
20
+    public void simMill(){
21
+        Simulation simmy = new Simulation(2,1_000_000);
22
+        Dice dice1 = new Dice();
23
+
24
+        for (int x = 1_000_000; x >= 0 ; x--){
25
+            Integer sum = dice1.roll(2);
26
+            // System.out.println(sum);
27
+            bin.counter(sum);
28
+
29
+        }
30
+        //print result
31
+        printer();
32
+
33
+    }
34
+
35
+    public void printer(){
36
+        Bin bin1 = new Bin();
37
+        for (int x = 2; x <= 12; x++){
38
+
39
+            float y = 1_000_000;
40
+            float z = (bin.getValue(x)/y)*(float)100.0 ;
41
+            StringBuilder star = new StringBuilder();
42
+
43
+            while (z > 0){
44
+                star.append("*");
45
+                z--;
46
+
47
+            }
48
+            String s = star.toString();
49
+            System.out.printf( "%3d : %7s: %.2f %s\n " , x, bin.getValue(x),
50
+                bin.getValue(x)/y, s);
51
+        }
52
+
53
+    }
54
+
55
+    public void simulation()
56
+    {
57
+        Scanner scanner = new Scanner(System.in);
58
+        Scanner close = new Scanner(System.in);
59
+        Dice dice = new Dice();
60
+        boolean result = true;
61
+
62
+        while(result == true){
63
+            System.out.println("How many dice would you like to roll?");
64
+            int die= scanner.nextInt();
65
+
66
+            if (die == 1){
67
+                System.out.println("You rolled a " + dice.roll(die) + ".");} else
68
+            if (die > 1){
69
+                System.out.println("The sum of your rolls is: " + dice.roll(die) + ".");
70
+            } else
71
+            if (die == 0){
72
+                System.out.println("All your base are belong to us.");
73
+            } else
74
+            if (die < 0){
75
+                System.out.println("No.");
76
+            }
77
+
78
+            System.out.println("do you want to exit? Yes or No");
79
+            String exit = close.nextLine();
80
+
81
+            if (exit.equalsIgnoreCase("No")) {
82
+                continue;
83
+            } else
84
+            if (exit.equalsIgnoreCase("Yes")){
85
+                break;
86
+            } else {
87
+                System.out.println("*Not a valid input*");
88
+            }
89
+
90
+        }
91
+        printer();
92
+
93
+    }
94
+
95
+}

+ 52
- 0
package.bluej Wyświetl plik

@@ -0,0 +1,52 @@
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=705
9
+editor.fx.0.width=1280
10
+editor.fx.0.x=0
11
+editor.fx.0.y=22
12
+objectbench.height=101
13
+objectbench.width=670
14
+package.divider.horizontal=0.6
15
+package.divider.vertical=0.8007380073800738
16
+package.editor.height=427
17
+package.editor.width=568
18
+package.editor.x=35
19
+package.editor.y=49
20
+package.frame.height=600
21
+package.frame.width=694
22
+package.numDependencies=2
23
+package.numTargets=3
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=Simulation
34
+target1.showInterface=false
35
+target1.type=ClassTarget
36
+target1.width=90
37
+target1.x=40
38
+target1.y=210
39
+target2.height=50
40
+target2.name=Bin
41
+target2.showInterface=false
42
+target2.type=ClassTarget
43
+target2.width=80
44
+target2.x=190
45
+target2.y=320
46
+target3.height=50
47
+target3.name=Dice
48
+target3.showInterface=false
49
+target3.type=ClassTarget
50
+target3.width=80
51
+target3.x=190
52
+target3.y=150