forked from Denisolt/CSCI-160
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBlackJack.java
More file actions
98 lines (90 loc) · 3.06 KB
/
BlackJack.java
File metadata and controls
98 lines (90 loc) · 3.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
//10.27.2015
//Denisolt
import java.util.Random;
import java.util.Scanner;
public class BlackJack
{
public static void main(String [] args)
{
Die1 game1 = new Die1(10);
int randomCard = game1.getValue();
do
{
Random rand = new Random ();
System.out.println("This is the blackjack card game");
int usertotal=0;
int sumcard=0;
int comptotal=0;
int userNum = randomCard + randomCard;
do
{
comptotal = compchoice(comptotal, randomCard);
usertotal = usertotal + randomCard;
System.out.println("You have " + usertotal);
System.out.println("Dealer has " + comptotal);
}
while(Playagain());
result(comptotal, usertotal);
System.out.println();
System.out.println();
}
while(Playagain2());
}
public static boolean Playagain()
{
String playAgain;
do
{
Scanner keyboard = new Scanner (System.in);
System.out.print("Do you want to continue (Y/N)?: ");
playAgain = keyboard.nextLine();
}
while(!playAgain.equalsIgnoreCase("y")&&!playAgain.equalsIgnoreCase("n"));
if (!playAgain.equalsIgnoreCase("y"))
return false;
else
return true;
}
public static int compchoice(int comptotal, int randomCard)
{
while (comptotal<=17)
{
int compNum = randomCard;
comptotal = comptotal + compNum;
}
return comptotal;
}
public static void result(int comptotal, int usertotal)
{
if (comptotal==usertotal)
System.out.println("It's draw, dealer has " + comptotal+ " and you have " + usertotal);
else if (usertotal==21)
System.out.println("You won, dealer has " + comptotal + " and you have " + usertotal);
else if(comptotal<=21&&usertotal<=21)
{
if((21-comptotal)<(21-usertotal))
System.out.println("Dealer won, he has " + comptotal+ " and you have " + usertotal);
else
System.out.println("You won, dealer has " + comptotal + " and you have " + usertotal);
}
else if (comptotal<=21&&usertotal>=21)
System.out.println("Dealer won, he has " + comptotal+ " and you have " + usertotal);
else if(comptotal>=21&&usertotal<=21)
System.out.println("You won, dealer has " + comptotal + " and you have " + usertotal);
}
public static boolean Playagain2()
{
String playAgain2;
do
{
Scanner keyboard = new Scanner (System.in);
System.out.print("Do you want to play again (Y/N)?: ");
playAgain2 = keyboard.nextLine();
}
while(!playAgain2.equalsIgnoreCase("y")&&!playAgain2.equalsIgnoreCase("n"));
if (!playAgain2.equalsIgnoreCase("y"))
return false;
else
return true;
}
}