Quellcode durchsuchen

DicePlayer class no more print statements

Lauren Green vor 6 Jahren
Ursprung
Commit
0cd8416b06

+ 8
- 5
src/main/java/io/zipcoder/casino/DicePlayer.java Datei anzeigen

@@ -19,19 +19,22 @@ public class DicePlayer {
19 19
         return cup;
20 20
     }
21 21
 
22
-    public void printCup() {
22
+    public String cupToString() {
23
+
24
+        String cupString = "";
25
+
23 26
         for(Dice d : cup) {
24
-            System.out.print(d.getValue() + " ");
27
+            cupString += (d.getValue() + " ");
25 28
         }
26
-        System.out.println();
29
+        return cupString;
27 30
     }
28 31
 
29 32
     public Player getPlayer() {
30 33
         return player;
31 34
     }
32 35
 
33
-    public void printBalanceAtEnd() {
34
-        System.out.println("Your total balance is now: $" + getPlayer().getCurrentBalance());
36
+    public String balanceAtEnd() {
37
+        return "Your total balance is now: $" + getPlayer().getCurrentBalance();
35 38
     }
36 39
 }
37 40
 

+ 2
- 4
src/main/java/io/zipcoder/casino/Yahtzee.java Datei anzeigen

@@ -6,7 +6,7 @@ import java.util.Scanner;
6 6
 public class Yahtzee extends DiceGame implements Game, Gamble {
7 7
 
8 8
     DicePlayer dicePlayer;
9
-    private Scanner scanner = new Scanner(System.in);
9
+    Console console = new Console();
10 10
     int betAmount = 0;
11 11
 
12 12
     public Yahtzee(Player player) {
@@ -37,9 +37,7 @@ public class Yahtzee extends DiceGame implements Game, Gamble {
37 37
 
38 38
     public void startGame() {
39 39
         createGame();
40
-
41
-        System.out.println("How much would you like to bet on this game?");
42
-        int betAmount = scanner.nextInt();
40
+        int betAmount = console.getIntFromUser("How much would you like to bet on this game?");
43 41
         setBid(betAmount);
44 42
         bet(betAmount);
45 43