ソースを参照

merged sims tests and slots

Jonathan Hinds 6 年 前
コミット
14c9964ecc

+ 213
- 1
src/.idea/workspace.xml ファイルの表示

@@ -1,9 +1,221 @@
1 1
 <?xml version="1.0" encoding="UTF-8"?>
2 2
 <project version="4">
3
+  <component name="ChangeListManager">
4
+    <list default="true" id="74cab72c-e027-4e61-ac26-2617cf8ce683" name="Default Changelist" comment="">
5
+      <change afterPath="$PROJECT_DIR$/.idea/misc.xml" afterDir="false" />
6
+      <change afterPath="$PROJECT_DIR$/.idea/modules.xml" afterDir="false" />
7
+      <change afterPath="$PROJECT_DIR$/.idea/vcs.xml" afterDir="false" />
8
+      <change afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
9
+      <change afterPath="$PROJECT_DIR$/test/java/io/zipcoder/casino/SlotTest.java" afterDir="false" />
10
+      <change beforePath="$PROJECT_DIR$/main/java/io/zipcoder/casino/Casino.java" beforeDir="false" afterPath="$PROJECT_DIR$/main/java/io/zipcoder/casino/Casino.java" afterDir="false" />
11
+      <change beforePath="$PROJECT_DIR$/main/java/io/zipcoder/casino/Game.java" beforeDir="false" afterPath="$PROJECT_DIR$/main/java/io/zipcoder/casino/Game.java" afterDir="false" />
12
+      <change beforePath="$PROJECT_DIR$/main/java/io/zipcoder/casino/Printer.java" beforeDir="false" afterPath="$PROJECT_DIR$/main/java/io/zipcoder/casino/Printer.java" afterDir="false" />
13
+      <change beforePath="$PROJECT_DIR$/main/java/io/zipcoder/casino/SlotMachine.java" beforeDir="false" afterPath="$PROJECT_DIR$/main/java/io/zipcoder/casino/SlotMachine.java" afterDir="false" />
14
+      <change beforePath="$PROJECT_DIR$/main/java/io/zipcoder/casino/Yahtzee.java" beforeDir="false" afterPath="$PROJECT_DIR$/main/java/io/zipcoder/casino/Yahtzee.java" afterDir="false" />
15
+      <change beforePath="$PROJECT_DIR$/test/java/io/zipcoder/casino/CardTest.java" beforeDir="false" afterPath="$PROJECT_DIR$/test/java/io/zipcoder/casino/CardTest.java" afterDir="false" />
16
+    </list>
17
+    <option name="EXCLUDED_CONVERTED_TO_IGNORED" value="true" />
18
+    <option name="SHOW_DIALOG" value="false" />
19
+    <option name="HIGHLIGHT_CONFLICTS" value="true" />
20
+    <option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
21
+    <option name="LAST_RESOLUTION" value="IGNORE" />
22
+  </component>
23
+  <component name="FUSProjectUsageTrigger">
24
+    <session id="729355978">
25
+      <usages-collector id="statistics.lifecycle.project">
26
+        <counts>
27
+          <entry key="project.closed" value="1" />
28
+          <entry key="project.open.time.1" value="1" />
29
+          <entry key="project.opened" value="1" />
30
+        </counts>
31
+      </usages-collector>
32
+      <usages-collector id="statistics.file.extensions.open">
33
+        <counts>
34
+          <entry key="java" value="1" />
35
+        </counts>
36
+      </usages-collector>
37
+      <usages-collector id="statistics.file.types.open">
38
+        <counts>
39
+          <entry key="JAVA" value="1" />
40
+        </counts>
41
+      </usages-collector>
42
+    </session>
43
+  </component>
44
+  <component name="FileEditorManager">
45
+    <leaf>
46
+      <file pinned="false" current-in-tab="true">
47
+        <entry file="file://$PROJECT_DIR$/test/java/io/zipcoder/casino/CardTest.java">
48
+          <provider selected="true" editor-type-id="text-editor">
49
+            <state relative-caret-position="60">
50
+              <caret line="4" column="30" lean-forward="true" selection-start-line="4" selection-start-column="30" selection-end-line="4" selection-end-column="30" />
51
+              <folding>
52
+                <element signature="imports" expanded="true" />
53
+              </folding>
54
+            </state>
55
+          </provider>
56
+        </entry>
57
+      </file>
58
+    </leaf>
59
+  </component>
60
+  <component name="Git.Settings">
61
+    <option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$/.." />
62
+  </component>
63
+  <component name="JsBuildToolGruntFileManager" detection-done="true" sorting="DEFINITION_ORDER" />
64
+  <component name="JsBuildToolPackageJson" detection-done="true" sorting="DEFINITION_ORDER" />
65
+  <component name="JsGulpfileManager">
66
+    <detection-done>true</detection-done>
67
+    <sorting>DEFINITION_ORDER</sorting>
68
+  </component>
69
+  <component name="ProjectFrameBounds" extendedState="6" fullScreen="true">
70
+    <option name="y" value="23" />
71
+    <option name="width" value="1440" />
72
+    <option name="height" value="817" />
73
+  </component>
74
+  <component name="ProjectLevelVcsManager" settingsEditedManually="true" />
75
+  <component name="ProjectView">
76
+    <navigator proportions="" version="1">
77
+      <foldersAlwaysOnTop value="true" />
78
+    </navigator>
79
+    <panes>
80
+      <pane id="ProjectPane">
81
+        <subPane>
82
+          <expand>
83
+            <path>
84
+              <item name="src" type="b2602c69:ProjectViewProjectNode" />
85
+              <item name="src" type="462c0819:PsiDirectoryNode" />
86
+            </path>
87
+            <path>
88
+              <item name="src" type="b2602c69:ProjectViewProjectNode" />
89
+              <item name="src" type="462c0819:PsiDirectoryNode" />
90
+              <item name="main" type="462c0819:PsiDirectoryNode" />
91
+            </path>
92
+            <path>
93
+              <item name="src" type="b2602c69:ProjectViewProjectNode" />
94
+              <item name="src" type="462c0819:PsiDirectoryNode" />
95
+              <item name="main" type="462c0819:PsiDirectoryNode" />
96
+              <item name="java" type="462c0819:PsiDirectoryNode" />
97
+            </path>
98
+            <path>
99
+              <item name="src" type="b2602c69:ProjectViewProjectNode" />
100
+              <item name="src" type="462c0819:PsiDirectoryNode" />
101
+              <item name="main" type="462c0819:PsiDirectoryNode" />
102
+              <item name="java" type="462c0819:PsiDirectoryNode" />
103
+              <item name="casino" type="462c0819:PsiDirectoryNode" />
104
+            </path>
105
+            <path>
106
+              <item name="src" type="b2602c69:ProjectViewProjectNode" />
107
+              <item name="src" type="462c0819:PsiDirectoryNode" />
108
+              <item name="test" type="462c0819:PsiDirectoryNode" />
109
+            </path>
110
+            <path>
111
+              <item name="src" type="b2602c69:ProjectViewProjectNode" />
112
+              <item name="src" type="462c0819:PsiDirectoryNode" />
113
+              <item name="test" type="462c0819:PsiDirectoryNode" />
114
+              <item name="java" type="462c0819:PsiDirectoryNode" />
115
+            </path>
116
+            <path>
117
+              <item name="src" type="b2602c69:ProjectViewProjectNode" />
118
+              <item name="src" type="462c0819:PsiDirectoryNode" />
119
+              <item name="test" type="462c0819:PsiDirectoryNode" />
120
+              <item name="java" type="462c0819:PsiDirectoryNode" />
121
+              <item name="casino" type="462c0819:PsiDirectoryNode" />
122
+            </path>
123
+          </expand>
124
+          <select />
125
+        </subPane>
126
+      </pane>
127
+      <pane id="PackagesPane" />
128
+      <pane id="Scope" />
129
+    </panes>
130
+  </component>
3 131
   <component name="PropertiesComponent">
132
+    <property name="WebServerToolWindowFactoryState" value="false" />
133
+    <property name="aspect.path.notification.shown" value="true" />
134
+    <property name="com.android.tools.idea.instantapp.provision.ProvisionBeforeRunTaskProvider.myTimeStamp" value="1541771782363" />
135
+    <property name="last_opened_file_path" value="$PROJECT_DIR$" />
4 136
     <property name="nodejs_interpreter_path.stuck_in_default_project" value="undefined stuck path" />
5 137
     <property name="nodejs_npm_path_reset_for_default_project" value="true" />
6
-    <property name="settings.editor.selected.configurable" value="preferences.lookFeel" />
138
+    <property name="settings.editor.selected.configurable" value="preferences.general" />
139
+  </component>
140
+  <component name="RunDashboard">
141
+    <option name="ruleStates">
142
+      <list>
143
+        <RuleState>
144
+          <option name="name" value="ConfigurationTypeDashboardGroupingRule" />
145
+        </RuleState>
146
+        <RuleState>
147
+          <option name="name" value="StatusDashboardGroupingRule" />
148
+        </RuleState>
149
+      </list>
150
+    </option>
151
+  </component>
152
+  <component name="SvnConfiguration">
153
+    <configuration />
154
+  </component>
155
+  <component name="TaskManager">
156
+    <task active="true" id="Default" summary="Default task">
157
+      <changelist id="74cab72c-e027-4e61-ac26-2617cf8ce683" name="Default Changelist" comment="" />
158
+      <created>1541771578720</created>
159
+      <option name="number" value="Default" />
160
+      <option name="presentableId" value="Default" />
161
+      <updated>1541771578720</updated>
162
+      <workItem from="1541771580200" duration="204000" />
163
+    </task>
164
+    <servers />
165
+  </component>
166
+  <component name="TimeTrackingManager">
167
+    <option name="totallyTimeSpent" value="204000" />
168
+  </component>
169
+  <component name="ToolWindowManager">
170
+    <frame x="0" y="0" width="1440" height="900" extended-state="6" />
171
+    <editor active="true" />
172
+    <layout>
173
+      <window_info id="Image Layers" />
174
+      <window_info id="Designer" />
175
+      <window_info id="UI Designer" />
176
+      <window_info id="Capture Tool" />
177
+      <window_info id="Favorites" side_tool="true" />
178
+      <window_info active="true" content_ui="combo" id="Project" order="0" visible="true" weight="0.24964234" />
179
+      <window_info id="Structure" order="1" side_tool="true" weight="0.25" />
180
+      <window_info anchor="bottom" id="Database Changes" show_stripe_button="false" />
181
+      <window_info anchor="bottom" id="Version Control" show_stripe_button="false" />
182
+      <window_info anchor="bottom" id="Terminal" />
183
+      <window_info anchor="bottom" id="Event Log" side_tool="true" />
184
+      <window_info anchor="bottom" id="Message" order="0" />
185
+      <window_info anchor="bottom" id="Find" order="1" />
186
+      <window_info anchor="bottom" id="Run" order="2" />
187
+      <window_info anchor="bottom" id="Debug" order="3" weight="0.4" />
188
+      <window_info anchor="bottom" id="Cvs" order="4" weight="0.25" />
189
+      <window_info anchor="bottom" id="Inspection" order="5" weight="0.4" />
190
+      <window_info anchor="bottom" id="TODO" order="6" />
191
+      <window_info anchor="right" id="Palette" />
192
+      <window_info anchor="right" id="Theme Preview" />
193
+      <window_info anchor="right" id="Capture Analysis" />
194
+      <window_info anchor="right" id="Palette&#9;" />
195
+      <window_info anchor="right" id="Database" />
196
+      <window_info anchor="right" id="Maven Projects" />
197
+      <window_info anchor="right" id="Commander" internal_type="SLIDING" order="0" type="SLIDING" weight="0.4" />
198
+      <window_info anchor="right" id="Ant Build" order="1" weight="0.25" />
199
+      <window_info anchor="right" content_ui="combo" id="Hierarchy" order="2" weight="0.25" />
200
+    </layout>
201
+  </component>
202
+  <component name="TypeScriptGeneratedFilesManager">
203
+    <option name="version" value="1" />
204
+  </component>
205
+  <component name="VcsContentAnnotationSettings">
206
+    <option name="myLimit" value="2678400000" />
207
+  </component>
208
+  <component name="editorHistoryManager">
209
+    <entry file="file://$PROJECT_DIR$/test/java/io/zipcoder/casino/CardTest.java">
210
+      <provider selected="true" editor-type-id="text-editor">
211
+        <state relative-caret-position="60">
212
+          <caret line="4" column="30" lean-forward="true" selection-start-line="4" selection-start-column="30" selection-end-line="4" selection-end-column="30" />
213
+          <folding>
214
+            <element signature="imports" expanded="true" />
215
+          </folding>
216
+        </state>
217
+      </provider>
218
+    </entry>
7 219
   </component>
8 220
   <component name="masterDetails">
9 221
     <states>

+ 7
- 1
src/main/java/io/zipcoder/casino/Casino.java ファイルの表示

@@ -67,9 +67,15 @@ public class Casino {
67 67
 
68 68
                 case 4:
69 69
                     int slotBet1= console.getIntFromUser("Enter the amount you want to bet on Slot");
70
+                    if ((slotBet1 < 0) || (slotBet1 >100) )
71
+                    {
72
+                        Printer.printMessage("Invalid bet amount entered, min bet for slot is $1 and max $100 ");
73
+                        break;
74
+                    }
70 75
                     Game slot= new SlotMachine(slotBet1);
71
-                    slot.startGame();
72 76
                     game = slot;
77
+                    slot.startGame();
78
+                    ((SlotMachine) slot).slotResult();
73 79
                     ((SlotMachine) slot).payout();
74 80
                     break;
75 81
 

+ 70
- 73
src/main/java/io/zipcoder/casino/SlotMachine.java ファイルの表示

@@ -1,13 +1,17 @@
1 1
 package io.zipcoder.casino;
2 2
 
3 3
 import java.util.Random;
4
-import java.util.Scanner;
5
-
6
-import static java.lang.Thread.sleep;
7 4
 
8 5
 public class SlotMachine implements Game, Gamble {
9 6
     private int betAmount;
10
-    private int payout=0;
7
+    private int payoutAmt=0;
8
+    String word="";
9
+    String outputword="";
10
+
11
+    String word1="";
12
+    String word2="";
13
+    String word3="";
14
+    double totalBet=0;
11 15
 
12 16
     public SlotMachine(int betAmount) {
13 17
         this.betAmount = betAmount;
@@ -18,9 +22,8 @@ public class SlotMachine implements Game, Gamble {
18 22
         this.betAmount= betAmount;
19 23
     }
20 24
 
21
-    @Override
22 25
     public void payout(){
23
-        Printer.printMessage("Your payout amount for slot machine is: $" + payout + "\n");
26
+        Printer.printMessage("Your payout amount for slot machine is: $" + payoutAmt + "\n");
24 27
     }
25 28
 
26 29
     @Override
@@ -31,7 +34,7 @@ public class SlotMachine implements Game, Gamble {
31 34
         } catch (InterruptedException e) {
32 35
             e.printStackTrace();
33 36
         }
34
-        Printer.printMessage("Your slot is in progress"+"\n");
37
+        Printer.printMessage("Your slot is in progress" + "\n");
35 38
 
36 39
         try {
37 40
             Thread.sleep(3000);
@@ -39,85 +42,65 @@ public class SlotMachine implements Game, Gamble {
39 42
             e.printStackTrace();
40 43
         }
41 44
 
42
-        String word="";
43
-        String outputword="";
44
-        String word1="";
45
-        String word2="";
46
-        String word3="";
47
-        //int useramount=0;
48
-        char playAgain= 'y';
49
-        double totalBet=0;
50
-
51
-       // while(playAgain=='y'){
52
-
53
-            outputword="";
54
-
55
-            Random rand = new Random();
56
-
57
-            for(int i = 1; i <=3;i++){
58
-                int randnum = rand.nextInt(6);
59
-                //System.out.println(randnum);
60
-
61
-                if(randnum == 0) {
62
-                    word = "DOG";
63
-                  //  System.out.println("dog");
64
-                }
65
-                else if(randnum == 1) {
66
-                    word = "CAT";
67
-                  //  System.out.println("cat");
68
-                }
69
-                else if(randnum == 2) {
70
-                    word = "RABBIT";
71
-                  //  System.out.println("kjsd");
72
-                }
73
-                else if(randnum == 3) {
74
-                    word = "SQUIRREL";
75
-                  //  System.out.println("sq");
76
-                }
77
-                else if(randnum == 4) {
78
-                    word = "FISH";
79
-                  //  System.out.println("ff");
80
-                }
81
-                else if(randnum == 5) {
82
-                    word = "MOUSE";
83
-                  //  System.out.println("mm");
84
-                }
85
-                // outputword += word;
86
-
87
-                if(i == 1){
88
-                    word1= word;
89
-                //    System.out.println(i);
90
-                }
91
-
92
-                else if(i == 2){
93
-                    word2= word;
94
-                  //  System.out.println(i);
95
-                }
96
-
97
-                else if(i == 3){
98
-                    word3= word;
99
-                   // System.out.println(word3);
100
-                }
45
+
46
+        outputword = "";
47
+
48
+        Random rand = new Random();
49
+
50
+        for (int i = 1; i <= 3; i++) {
51
+            int randnum = rand.nextInt(6);
52
+
53
+
54
+            if (randnum == 0) {
55
+                word = "DOG";
56
+
57
+            } else if (randnum == 1) {
58
+                word = "CAT";
59
+
60
+            } else if (randnum == 2) {
61
+                word = "RABBIT";
62
+
63
+            } else if (randnum == 3) {
64
+                word = "SQUIRREL";
65
+
66
+            } else if (randnum == 4) {
67
+                word = "FISH";
68
+
69
+            } else if (randnum == 5) {
70
+                word = "MOUSE";
71
+
101 72
             }
73
+
74
+            if (i == 1) {
75
+                word1 = word;
76
+            } else if (i == 2) {
77
+                word2 = word;
78
+            } else if (i == 3) {
79
+                word3 = word;
80
+            }
81
+        }
82
+
83
+    }
84
+
85
+    public void slotResult()
86
+    {
102 87
             outputword= "[ " + word1+ " ]" + "   " + "[ " + word2 + " ]" + "   "+ "[ " + word3 + " ]" + "\n" ;
103 88
 
104 89
             if(((!word1.equals(word2)) )&& ((!word1.equals(word3))) && ((!word2.equals(word3)))){
105 90
 
106 91
                 outputword= outputword + "\n"+" You have won $0";
107
-                payout=0;
92
+                payoutAmt=0;
108 93
             }
109
-
110
-            else if( ((word1.equals(word2) == true) && (word1.equals(word3)== false )) || ((word1.equals(word3)== true) && (word1.equals(word2)==false)) || ( (word2.equals(word3)==true) && (word2.equals(word1))==false)){
94
+            else if( (word1.equals(word2) && (!word1.equals(word3))) || ((word1.equals(word3)) && (!word1.equals(word2))) || ((word2.equals(word3)) && (!word2.equals(word1)))){
111 95
 
112 96
                 outputword= outputword + "\n" +" You have won $" + (betAmount*2);
113
-                payout=betAmount*2;
97
+                payoutAmt=betAmount*2;
114 98
             }
115 99
 
116 100
 
117
-            else if( ((word1.equals(word2)==true) && (word1.equals(word3)==true) ) && ((word2.equals(word1)==true) && (word2.equals(word3)==true)) && ( (word3.equals(word1)==true) && (word3.equals(word2)==true))){
118
-
101
+            else if(word1.equals(word2) && word1.equals(word3)  /*&& ((word2.equals(word1)) && (word2.equals(word3))) && ( (word3.equals(word1)) && (word3.equals(word2)))*/){
119 102
                 outputword= outputword + "\n" + "You have won $" + (betAmount*3);
120
-                payout=betAmount*3;
103
+                payoutAmt=betAmount*3;
121 104
             }
122 105
 
123 106
             Printer.printMessage(( outputword + "\n" ));
@@ -133,5 +116,19 @@ public class SlotMachine implements Game, Gamble {
133 116
     public void startRound() {
134 117
 
135 118
     }
119
+    public int getPayoutAmt() {
120
+        return payoutAmt;
121
+    }
122
+    public void setWord1(String word1) {
123
+        this.word1 = word1;
124
+    }
125
+
126
+    public void setWord2(String word2) {
127
+        this.word2 = word2;
128
+    }
129
+
130
+    public void setWord3(String word3) {
131
+        this.word3 = word3;
132
+    }
136 133
 }
137 134
 

+ 0
- 1
src/main/java/io/zipcoder/casino/Yahtzee.java ファイルの表示

@@ -194,7 +194,6 @@ public class Yahtzee extends DiceGame implements Game, Gamble {
194 194
         Printer.printMessage("You won $" + payOut);
195 195
     }
196 196
 
197
-
198 197
     public DicePlayer getDicePlayer() {
199 198
         return dicePlayer;
200 199
     }

+ 13
- 13
src/test/java/io/zipcoder/casino/CardTest.java ファイルの表示

@@ -6,17 +6,17 @@ import javax.smartcardio.Card;
6 6
 
7 7
 public class CardTest {
8 8
 
9
-    @Test
10
-    public void createCard(){
11
-        Card card = new Card(Card.CardValue.TWO, Card.Suit.CLUBS);
12
-        System.out.println(card.getName());
13
-    }
14
-
15
-    @Test
16
-    public void createCard2(){
17
-        Card card = new Card(Card.CardValue.TWO, Card.Suit.CLUBS);
18
-        Card card1 = new Card(Card.CardValue.QUEEN, Card.Suit.HEARTS);
19
-        System.out.println(card.getName());
20
-        System.out.println(card1.getName());
21
-    }
9
+//    @Test
10
+//    public void createCard(){
11
+//        Card card = new Card(Card.CardValue.TWO, Card.Suit.CLUBS);
12
+//        System.out.println(card.getName());
13
+//    }
14
+//
15
+//    @Test
16
+//    public void createCard2(){
17
+//        Card card = new Card(Card.CardValue.TWO, Card.Suit.CLUBS);
18
+//        Card card1 = new Card(Card.CardValue.QUEEN, Card.Suit.HEARTS);
19
+//        System.out.println(card.getName());
20
+//        System.out.println(card1.getName());
21
+//    }
22 22
 }

+ 18
- 7
src/test/java/io/zipcoder/casino/SlotTest.java ファイルの表示

@@ -4,8 +4,8 @@ package io.zipcoder.casino;
4 4
 import org.junit.Test;
5 5
 import org.junit.Assert;
6 6
 
7
-public class SlotTest {
8 7
 
8
+public class SlotTest {
9 9
 
10 10
     @Test
11 11
     public void testSlotResult1(){
@@ -15,9 +15,12 @@ public class SlotTest {
15 15
         String word3="MOUSE";
16 16
         //given
17 17
         SlotMachine slotmachine = new SlotMachine(betAmount);
18
+        slotmachine.setWord1(word1);
19
+        slotmachine.setWord2(word2);
20
+        slotmachine.setWord3(word3);
18 21
 
19 22
         slotmachine.slotResult();
20
-        int payout=slotmachine.payout;
23
+        int payout = slotmachine.getPayoutAmt();
21 24
         Assert.assertEquals(30,payout);
22 25
     }
23 26
 
@@ -28,11 +31,17 @@ public class SlotTest {
28 31
         String word1="MOUSE";
29 32
         String word2="MOUSE";
30 33
         String word3="CAT";
34
+
35
+
31 36
         //given
32 37
         SlotMachine slotmachine = new SlotMachine(betAmount);
33 38
 
39
+        slotmachine.setWord1(word1);
40
+        slotmachine.setWord2(word2);
41
+        slotmachine.setWord3(word3);
42
+
34 43
         slotmachine.slotResult();
35
-        int payout=slotmachine.payout;
44
+        int payout=slotmachine.getPayoutAmt();
36 45
         Assert.assertEquals(20,payout);
37 46
 
38 47
     }
@@ -43,15 +52,17 @@ public class SlotTest {
43 52
         String word1="MOUSE";
44 53
         String word2="RABBIT";
45 54
         String word3="CAT";
55
+
46 56
         //given
47 57
         SlotMachine slotmachine = new SlotMachine(betAmount);
48 58
 
59
+        slotmachine.setWord1(word1);
60
+        slotmachine.setWord2(word2);
61
+        slotmachine.setWord3(word3);
62
+
49 63
         slotmachine.slotResult();
50
-        int payout=slotmachine.payout;
64
+        int payout=slotmachine.getPayoutAmt();
51 65
         Assert.assertEquals(0,payout);
52 66
 
53 67
     }
54
-
55
-
56
-
57 68
 }