Aleena Rose-Mathew 6 年之前
父節點
當前提交
09cc67bc0f
共有 7 個檔案被更改,包括 153 行新增27 行删除
  1. 8
    0
      pom.xml
  2. 6
    0
      src/.idea/vcs.xml
  3. 52
    24
      src/.idea/workspace.xml
  4. 17
    0
      src/Test/DiceTest.java
  5. 14
    0
      src/main/java/AleenaResults.md
  6. 7
    3
      src/main/java/Dice.java
  7. 49
    0
      src/main/java/Simulation.java

+ 8
- 0
pom.xml 查看文件

@@ -7,6 +7,14 @@
7 7
     <groupId>com.zipcodewilmington</groupId>
8 8
     <artifactId>Dicey-Lab</artifactId>
9 9
     <version>1.0-SNAPSHOT</version>
10
+    <dependencies>
11
+        <dependency>
12
+            <groupId>junit</groupId>
13
+            <artifactId>junit</artifactId>
14
+            <version>RELEASE</version>
15
+            <scope>test</scope>
16
+        </dependency>
17
+    </dependencies>
10 18
 
11 19
 
12 20
 </project>

+ 6
- 0
src/.idea/vcs.xml 查看文件

@@ -0,0 +1,6 @@
1
+<?xml version="1.0" encoding="UTF-8"?>
2
+<project version="4">
3
+  <component name="VcsDirectoryMappings">
4
+    <mapping directory="$PROJECT_DIR$/.." vcs="Git" />
5
+  </component>
6
+</project>

+ 52
- 24
src/.idea/workspace.xml 查看文件

@@ -1,7 +1,9 @@
1 1
 <?xml version="1.0" encoding="UTF-8"?>
2 2
 <project version="4">
3 3
   <component name="ChangeListManager">
4
-    <list default="true" id="16a8cee9-f841-4436-a7b2-9a2208578679" name="Default" comment="" />
4
+    <list default="true" id="16a8cee9-f841-4436-a7b2-9a2208578679" name="Default" comment="">
5
+      <change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
6
+    </list>
5 7
     <option name="EXCLUDED_CONVERTED_TO_IGNORED" value="true" />
6 8
     <option name="TRACKING_ENABLED" value="true" />
7 9
     <option name="SHOW_DIALOG" value="false" />
@@ -28,24 +30,22 @@
28 30
           </provider>
29 31
         </entry>
30 32
       </file>
31
-      <file leaf-file-name="src.iml" pinned="false" current-in-tab="false">
32
-        <entry file="file://$PROJECT_DIR$/.idea/src.iml">
33
-          <provider selected="true" editor-type-id="text-editor" />
34
-        </entry>
35
-      </file>
36
-      <file leaf-file-name="workspace.xml" pinned="false" current-in-tab="false">
37
-        <entry file="file://$PROJECT_DIR$/.idea/workspace.xml">
38
-          <provider selected="true" editor-type-id="text-editor" />
39
-        </entry>
40
-      </file>
41
-      <file leaf-file-name="compiler.xml" pinned="false" current-in-tab="false">
42
-        <entry file="file://$PROJECT_DIR$/.idea/compiler.xml">
43
-          <provider selected="true" editor-type-id="text-editor" />
33
+      <file leaf-file-name="Dice.java" pinned="false" current-in-tab="false">
34
+        <entry file="file://$PROJECT_DIR$/main/java/Dice.java">
35
+          <provider selected="true" editor-type-id="text-editor">
36
+            <state>
37
+              <caret selection-end-line="18" />
38
+            </state>
39
+          </provider>
44 40
         </entry>
45 41
       </file>
46
-      <file leaf-file-name="Dice.java" pinned="false" current-in-tab="true">
47
-        <entry file="file://$PROJECT_DIR$/main/java/Dice.java">
48
-          <provider selected="true" editor-type-id="text-editor" />
42
+      <file leaf-file-name="DiceTest.java" pinned="false" current-in-tab="true">
43
+        <entry file="file://$PROJECT_DIR$/Test/DiceTest.java">
44
+          <provider selected="true" editor-type-id="text-editor">
45
+            <state relative-caret-position="195">
46
+              <caret line="13" lean-forward="true" selection-start-line="13" selection-end-line="13" />
47
+            </state>
48
+          </provider>
49 49
         </entry>
50 50
       </file>
51 51
       <file leaf-file-name="Simulation.java" pinned="false" current-in-tab="false">
@@ -55,10 +55,21 @@
55 55
       </file>
56 56
     </leaf>
57 57
   </component>
58
+  <component name="FileTemplateManagerImpl">
59
+    <option name="RECENT_TEMPLATES">
60
+      <list>
61
+        <option value="Class" />
62
+      </list>
63
+    </option>
64
+  </component>
65
+  <component name="Git.Settings">
66
+    <option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$/.." />
67
+  </component>
58 68
   <component name="IdeDocumentHistory">
59 69
     <option name="CHANGED_PATHS">
60 70
       <list>
61 71
         <option value="$PROJECT_DIR$/main/java/Bins.java" />
72
+        <option value="$PROJECT_DIR$/Test/DiceTest.java" />
62 73
       </list>
63 74
     </option>
64 75
   </component>
@@ -83,6 +94,7 @@
83 94
     <option name="width" value="1280" />
84 95
     <option name="height" value="714" />
85 96
   </component>
97
+  <component name="ProjectLevelVcsManager" settingsEditedManually="true" />
86 98
   <component name="ProjectView">
87 99
     <navigator proportions="" version="1">
88 100
       <foldersAlwaysOnTop value="true" />
@@ -103,6 +115,11 @@
103 115
               <item name="src" type="462c0819:PsiDirectoryNode" />
104 116
               <item name=".idea" type="462c0819:PsiDirectoryNode" />
105 117
             </path>
118
+            <path>
119
+              <item name="src" type="b2602c69:ProjectViewProjectNode" />
120
+              <item name="src" type="462c0819:PsiDirectoryNode" />
121
+              <item name="Test" type="462c0819:PsiDirectoryNode" />
122
+            </path>
106 123
           </expand>
107 124
           <select />
108 125
         </subPane>
@@ -186,12 +203,12 @@
186 203
       <option name="presentableId" value="Default" />
187 204
       <updated>1529974567368</updated>
188 205
       <workItem from="1529974568951" duration="84000" />
189
-      <workItem from="1529974828671" duration="531000" />
206
+      <workItem from="1529974828671" duration="1372000" />
190 207
     </task>
191 208
     <servers />
192 209
   </component>
193 210
   <component name="TimeTrackingManager">
194
-    <option name="totallyTimeSpent" value="615000" />
211
+    <option name="totallyTimeSpent" value="1456000" />
195 212
   </component>
196 213
   <component name="ToolWindowManager">
197 214
     <frame x="0" y="23" width="1280" height="714" extended-state="6" />
@@ -202,15 +219,15 @@
202 219
       <window_info anchor="right" id="Palette&#9;" order="3" />
203 220
       <window_info id="Image Layers" order="2" />
204 221
       <window_info anchor="right" id="Capture Analysis" order="3" />
205
-      <window_info anchor="bottom" id="Event Log" order="7" side_tool="true" />
222
+      <window_info anchor="bottom" id="Event Log" order="7" sideWeight="0.50080776" side_tool="true" visible="true" weight="0.23662885" />
206 223
       <window_info anchor="right" id="Maven Projects" order="3" />
207 224
       <window_info anchor="bottom" id="Database Changes" order="7" show_stripe_button="false" />
208 225
       <window_info anchor="bottom" id="Run" order="2" />
209
-      <window_info anchor="bottom" id="Version Control" order="7" show_stripe_button="false" />
210
-      <window_info anchor="bottom" id="Terminal" order="7" />
226
+      <window_info anchor="bottom" id="Version Control" order="7" />
227
+      <window_info active="true" anchor="bottom" id="Terminal" order="7" sideWeight="0.49919224" visible="true" weight="0.23662885" />
211 228
       <window_info id="Capture Tool" order="2" />
212 229
       <window_info id="Designer" order="2" />
213
-      <window_info active="true" content_ui="combo" id="Project" order="0" visible="true" weight="0.2536349" />
230
+      <window_info content_ui="combo" id="Project" order="0" visible="true" weight="0.2536349" />
214 231
       <window_info anchor="right" id="Database" order="3" />
215 232
       <window_info id="Structure" order="1" side_tool="true" weight="0.25" />
216 233
       <window_info anchor="right" id="Ant Build" order="1" weight="0.25" />
@@ -282,7 +299,18 @@
282 299
       </provider>
283 300
     </entry>
284 301
     <entry file="file://$PROJECT_DIR$/main/java/Dice.java">
285
-      <provider selected="true" editor-type-id="text-editor" />
302
+      <provider selected="true" editor-type-id="text-editor">
303
+        <state>
304
+          <caret selection-end-line="18" />
305
+        </state>
306
+      </provider>
307
+    </entry>
308
+    <entry file="file://$PROJECT_DIR$/Test/DiceTest.java">
309
+      <provider selected="true" editor-type-id="text-editor">
310
+        <state relative-caret-position="195">
311
+          <caret line="13" lean-forward="true" selection-start-line="13" selection-end-line="13" />
312
+        </state>
313
+      </provider>
286 314
     </entry>
287 315
   </component>
288 316
   <component name="masterDetails">

+ 17
- 0
src/Test/DiceTest.java 查看文件

@@ -0,0 +1,17 @@
1
+
2
+
3
+import org.junit.Test;
4
+
5
+import static junit.framework.TestCase.assertTrue;
6
+
7
+public class DiceTest {
8
+    @Test
9
+    public void test1()
10
+    {
11
+        Dice die=new Dice();
12
+        int min=1;
13
+        int max=6;
14
+        int actual=die.diceSum();
15
+        assertTrue(min<=actual&&actual<=max);
16
+    }
17
+}

+ 14
- 0
src/main/java/AleenaResults.md 查看文件

@@ -0,0 +1,14 @@
1
+***
2
+Simulation of 2 dice tossed for 1000000 times.
3
+***
4
+ 2 :    27832: 0.03 **
5
+ 3 :    55710: 0.06 *****
6
+ 4 :    82828: 0.08 ********
7
+ 5 :   111527: 0.11 ***********
8
+ 6 :   138957: 0.14 *************
9
+ 7 :   166516: 0.17 ****************
10
+ 8 :   138547: 0.14 *************
11
+ 9 :   110950: 0.11 ***********
12
+10 :    83553: 0.08 ********
13
+11 :    55656: 0.06 *****
14
+12 :    27924: 0.03 **

+ 7
- 3
src/main/java/Dice.java 查看文件

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

+ 49
- 0
src/main/java/Simulation.java 查看文件

@@ -1,5 +1,54 @@
1 1
 public class Simulation {
2 2
 
3
+    Integer numberOfDice;
4
+    Integer numberOfTosses;
5
+    public Simulation(Integer numberOfDice,Integer numberOfTosses)
6
+    {
7
+            this.numberOfDice=numberOfDice;
8
+            this.numberOfTosses=numberOfTosses;
9
+    }
10
+    Bins results=new Bins();
11
+    public void runSimulation()
12
+    {
13
+        int c=0;
14
+        Dice dice=new Dice(numberOfDice);
15
+        Bins results=new Bins();
16
+        while(c<numberOfTosses)
17
+        {
18
+            int result=dice.diceSum();
19
+            c++;
20
+            results.increment(result);
21
+        }
22
+        printHeader();
23
+        printResults(results);
24
+
25
+    }
26
+    public float ratioofTosses(int numberofresult)
27
+    {
28
+        return (numberofresult/(float)numberOfTosses);
29
+    }
30
+    public void printHeader()
31
+    {
32
+        System.out.println("***\n"+"Simulation of "+numberOfDice+" dice tossed for "+numberOfTosses+" times.\n***");
33
+    }
34
+    public void printResults(Bins results)
35
+    {
36
+        for(int i=2;i<=12;i++)
37
+        {
38
+            float ratio=ratioofTosses(results.get(i));
39
+            StringBuilder stars=new StringBuilder();
40
+            for(int j=1;j<(ratio*100);j++)
41
+            {
42
+                stars.append("*");
43
+            }
44
+            System.out.println(String.format("%2s :%9s:%5.2f ",i,results.get(i),ratio)+stars.toString());
45
+        }
46
+    }
47
+
48
+    public static void main(String[] args) {
49
+        Simulation simulation=new Simulation(2,1000000);
50
+        simulation.runSimulation();
51
+    }
3 52
 
4 53
 
5 54
 }