I'm trying to create a blackjack program for school.
No matter what I've been doing, this keeps coming with errors.
My teacher says theres some logic errors, and i don't understand it.
import java.util.Scanner;
import java.util.Random;
public class BlackJack {
public static void YesNo(){
Scanner input = new Scanner(System.in);
int YesNo;
System.out.println("Would you like to begin?");
System.out.println("1 for yes, 2 for no.");
YesNo = input.nextInt();
if (YesNo == 1){
System.out.println("If you get a total below 16, you will be able to acuire a third card. Ace is either 1 or 11.");
System.out.println("We will now begin.");
}
while (YesNo == 2){
System.out.println("It will hopefully crash now.");
}
GameStart();
}
public static void Check(int Card1, int Card2, int Card3, int Dealer1, int Dealer2, int Dealer3, int NewCard, int DNewCard){
int CardTotal, DealerTotal;
int CValue1, CValue2, CValue3;
int DValue1, DValue2, DValue3;
if (Card1 >= 11){
CValue1 = (10);
}
if (Card1 < 11){
CValue1=Card1;
}
if (Card2 >= 11){
CValue2 = (10);
}
if (Card2 < 11){
CValue2=Card2;
}
if (NewCard == 1){
if (Card3 >= 11){
CValue3 = (10);
}
if (Card3 < 11){
CValue3=Card3;
}
}
if (Dealer1 >= 11){
DValue1 = (10);
}
if (Dealer1 < 11){
DValue1= Dealer1;
}
if (Dealer2 >= 11){
DValue2 = (10);
}
if (Dealer2 < 11){
DValue2= Dealer2;
}
if (DNewCard ==1){
if (Dealer3 >= 11){
DValue3 = (10);
}
if (Dealer3 < 11){
DValue3= Dealer3;
}
}
CardTotal = (CValue1+CValue2);
DealerTotal = (DValue1+DValue2);
if (DNewCard ==1){
DealerTotal = (DealerTotal+DValue3);
}
if (NewCard ==1){
CardTotal = (CardTotal+CValue3);
}
}
public static void DealerCards(int CardTotal){
Scanner input = new Scanner(System.in);
Random r = new Random();
int Dealer1, Dealer2, Dealer3;
int DValue1, DValue2, DValue3;
int DealerTotal;
int DNewCard;
Dealer1 = r.nextInt(13) +1;
Dealer2 = r.nextInt(13) +1;
Check(0, 0, 0, Dealer1, Dealer2, Dealer3, 0, DNewCard);
if(DealerTotal <= 16){
Dealer3 = r.nextInt(13) +1;
Check(0, 0, 0, Dealer1, Dealer2, Dealer3, 0, DNewCard);
}
Winner(CardTotal, DealerTotal);
}
public static void GameStart(){
Scanner input = new Scanner(System.in);
Random r = new Random();
int Card1, Card2, Card3;
int CValue1, CValue2, CValue3;
int CardTotal;
int NewCard;
Card1 = r.nextInt(13) + 1;
Card2 = r.nextInt(13) + 1;
Check(Card1, Card2, Card3, 0, 0, 0, NewCard, 0);
System.out.println("Your cards are" + Card1 +" and " + Card2 +" and the total is "+CardTotal);
if (CardTotal <= 16){
System.out.println("Your total is 16 or under, would you like a second card?");
System.out.println("1 for yes, 2 for no.");
NewCard = input.nextInt();
if (NewCard == 1){
Card3 = r.nextInt(13) +1;
Check(Card1, Card2, Card3, 0, 0, 0, NewCard, 0);
System.out.println("Your new card is " +Card3+" and you new total is "+CardTotal);
}
}
DealerCards(CardTotal);
}
public static void Winner(int CardTotal, int DealerTotal) {
System.out.println("The dealer has " +DealerTotal+" and you have "+CardTotal);
if (DealerTotal > CardTotal){
System.out.println("You have lost.");
}
if (CardTotal > DealerTotal){
System.out.println("You have won!");
}
if (DealerTotal == CardTotal){
System.out.println("It's a tie!");
}
}
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
YesNo();
}
}