import java.util.Scanner;

public class Card
{
private boolean rankBad;
private boolean suitBad;
private boolean invalid;
private boolean valid;
private int value;
private int altValue;
private int suit;
private int rank;
private int numValue;
private int status;
private boolean isJack;
private boolean isAce;
private String card;



public Card()
{
Scanner keyboard = new Scanner(System.in);
getCard();
}

private void getCard()
{
Scanner keyboard = new Scanner(System.in);
do
{
Hand.numCardsInHand++;
do
{
System.out.print("\n>Enter Card#" + Hand.numCardsInHand + ":");
card = keyboard.nextLine();
card = card.toLowerCase();
validateCard();
isAce();
isJack();

if (rankBad)//rankBad means invalid rank
{
System.out.print("\nInvalid card rank---try again\n");
}

if (suitBad)//suitBad means invalid suit
{
System.out.print("\nInvalid card suit---try again\n");
}
if(invalid)//invalid will be assigned if entry is invalid
{
System.out.print("\nInvalid card entry---try again\n");
}

}while (!(valid));

Hand.handValue = Hand.handValue+getNumValue();

}while (Hand.numCardsInHand < 2);

if (isAce)
{
Hand.altHandValue = Hand.handValue+getAltValue()-1;
}

if ((isAce) && (isJack))
{
System.out.print("\n>You have Blackjack");
}
else if (isAce)
{
System.out.print("\n>Your hand value is " + Hand.handValue + " and your alternate hand value is " + Hand.altHandValue);
}
else
{
System.out.print("\n>Your hand value is " + Hand.handValue);
}


while (Hand.handValue < Hand.stayValue)
{
System.out.print("\n>The Hand elects a hit.");
Hand.numCardsInHand++;
do
{
System.out.print("\n>Enter Card#" + Hand.numCardsInHand + ":");
card = keyboard.nextLine();
card = card.toLowerCase();
validateCard();
isAce();
isJack();

if (rankBad)//rankBad means invalid rank
{
System.out.print("\nInvalid card rank---try again\n");
}

else if (suitBad)//suitBad means invalid suit
{
System.out.print("\n>Invalid card suit---try again\n");
}
else if (invalid)//invalid will be assigned if entry is invalid
{
System.out.print("\n>Invalid card entry---try again\n");
}
}while ((rankBad) || (suitBad) || (invalid));



Hand.handValue = Hand.handValue+getNumValue();

if (isAce)
{
Hand.altHandValue = Hand.handValue+getAltValue()-1;

if ((Hand.altHandValue >= 22) && (Hand.altHandValue >= Hand.stayValue))
{
System.out.print("\n>Your hand value is " + Hand.handValue);
}
else if ((Hand.handValue >= 22) && (Hand.altHandValue >= 22))
{
System.out.print("\n>Your hand is a bust.");
}
else
{
System.out.print("\n>Your hand value is " + Hand.handValue + " and your alternate hand value is " + Hand.altHandValue);
}
}
else if (Hand.handValue >=22)
{
System.out.print("\n>Your hand is a bust.");
}
else
{
System.out.print("\n>Your hand value is " + Hand.handValue);
}
}

}

public boolean validateCard()
{
int offset = 0;



if (card.charAt(0) == '2')
{
offset = 0;

value = 2;
altValue = -1;
rank = 2;
numValue = 2;
status = 1;
isJack = false;
isAce = false;
rankBad = false;
}
else if (card.charAt(0) == '3')
{
offset = 0;

value = 3;
altValue = -1;
rank = 3;
numValue = 3;
status = 1;
isJack = false;
isAce = false;
rankBad = false;
}

else if (card.charAt(0) == '4')
{
offset = 0;

value = 4;
altValue = -1;
rank = 4;
numValue = 4;
status = 1;
isJack = false;
isAce = false;
rankBad = false;
}

else if (card.charAt(0) == '5')
{
offset = 0;

value = 5;
altValue = -1;
rank = 5;
numValue = 5;
status = 1;
isJack = false;
isAce = false;
rankBad = false;
}

else if (card.charAt(0) == '6')
{
offset = 0;

value = 6;
altValue = -1;
rank = 6;
numValue = 6;
status = 1;
isJack = false;
isAce = false;
rankBad = false;
}

else if (card.charAt(0) == '7')
{
offset = 0;

value = 7;
altValue = -1;
rank = 7;
numValue = 7;
status = 1;
isJack = false;
isAce = false;
rankBad = false;
}

else if (card.charAt(0) == '8')
{
offset = 0;

value = 8;
altValue = -1;
rank = 8;
numValue = 8;
status = 1;
isJack = false;
isAce = false;
rankBad = false;
}

else if (card.charAt(0) == '9')
{
offset = 0;

value = 9;
altValue = -1;
rank = 9;
numValue = 9;
status = 1;
isJack = false;
isAce = false;
rankBad = false;
}

else if (card.charAt(0) == 'j')
{
offset = 0;

value = 10;
altValue = -1;
rank = 11;
numValue = 10;
status = 1;
isJack = true;
isAce = false;
rankBad = false;
}

else if (card.charAt(0) == 'q')
{
offset = 0;

value = 10;
altValue = -1;
rank = 12;
numValue = 10;
status = 1;
isJack = false;
isAce = false;
rankBad = false;
}

else if (card.charAt(0) == 'k')
{
offset = 0;

value = 10;
altValue = -1;
rank = 13;
numValue = 10;
status = 1;
isJack = false;
isAce = false;
rankBad = false;
}

else if (card.charAt(0) == 'a')
{
offset = 0;

value = 1;
altValue = 11;
rank = 14;
numValue = 1;
status = 1;
isJack = false;
isAce = true;
rankBad = false;
}

else if (card.startsWith("10"))
{
offset = 1;

value = 10;
altValue = -1;
rank = 10;
numValue = 10;
status = 1;
isJack = false;
isAce = false;
rankBad = false;
}

else
{
value = 0;
altValue = -1;
rank = 0;
numValue = 0;
isJack = false;
isAce = false;
rankBad = true;
}


if (card.charAt(1+offset) == '-')
{
if (card.charAt(2+offset) == 'c')
{
suit = 1;
suitBad = false;
valid = true;

}
else if (card.charAt(2+offset) == 's')
{
suit = 2;
suitBad = false;
valid = true;
}
else if (card.charAt(2+offset) == 'd')
{
suit = 3;
suitBad = false;
valid = true;
}
else if (card.charAt(2+offset) == 'h')
{
suit = 4;
suitBad = false;
valid = true;
}
else
{
suitBad = true;
}
}

else
{
invalid = true;
return invalid;
}

if ((rankBad) || (suitBad))
{
invalid = true;
return invalid;
}
else if (rankBad)
{
return rankBad;
}
else if (suitBad)
{
return suitBad;
}
else
{
return valid;
}

public int getNumValue()
{
return numValue;
}

public int getCardSuit()
{
return suit;
}

public int getCardValue()
{
return value;
}

public int getAltValue()
{
return altValue;
}

public boolean isJack()
{
return isJack;
}

public boolean isAce()
{
return isAce;
}

public int getCardRank()
{
return rank;
}
}

now the error keeps coming up with my public int lines at the bottom, if i comment one out it will give me an error for the next one. any help would be greatly appreciated.

The exception tells you exactly where the error occured. Somewhere directly before that point you have forgotten a ; or a closing } or are performing an action that must be contained within a method or constructor.

I'm surprised that this would be the error you get for it, but aren't you trying to declare those functions inside of your validateCard function?

Sure looks like it, which means that that is where he forgot the closing }

P.S. @OP use a switch that huge if/else if klotz hurts the eyes.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.