Results 1 to 3 of 3
Thread: Syntax error driving me nuts
- 03-25-2011, 06:21 AM #1
Member
- Join Date
- Mar 2011
- Posts
- 1
- Rep Power
- 0
Syntax error driving me nuts
So I have to build a program that runs a game of BlackJack between you and the computer. I have it all mapped it, but I cannot find the syntax error!
The error reads:
Multiple markers at this line
- Syntax error, insert "EnumBody" to complete BlockStatements
- Syntax error, insert "enum Identifier" to complete EnumHeaderName
It's found in Line 48 of my program, where it reads:
private static nextChar();
Here is my BlackJackTest.java class, let's see if you guys can help me out here!
import java.util.Scanner;
public class BlackJackTest {
public static void main(String[] args) {
int money; // Amount of money the user has.
int bet; // Amount user bets on a game.
boolean userWins; // Did the user win the game?
Scanner sc = new Scanner(System.in);
System.out.println("Welcome to the game of blackjack.");
System.out.println();
money = 1000; // User starts with $1,000.
while (true) {
System.out.println("You have " + money + " dollars.");
do {
System.out.println("How many dollars do you want to bet? (Enter 1 to end.)");
System.out.println("? ");
bet = sc.nextInt();
if (bet < 1 || bet > money)
System.out.println("Your answer must be between 0 and " + money + '.');
} while (bet < 1 || bet > money);
if (bet == 1)
break;
userWins = playBlackjack();
if (userWins)
money = money + bet;
else
money = money - bet;
System.out.println();
if (money == 0) {
System.out.println("Looks like you've are out of money!");
break;
}
}
System.out.println();
System.out.println("You leave with $" + money + '.');
} // end main()
static boolean playBlackjack() {
private static nextChar();
// Let the user play one game of Blackjack.
// Return true if the user wins, false if the user loses.
Deck deck; // A deck of cards. A new deck for each game.
Game dealerHand; // The dealer's hand.
Game userHand; // The user's hand.
deck = new Deck();
dealerHand = new Game();
userHand = new Game();
// Shuffle the deck, then deal two cards to each player.
deck.shuffle();
dealerHand.addCard( deck.dealCard() );
dealerHand.addCard( deck.dealCard() );
userHand.addCard( deck.dealCard() );
userHand.addCard( deck.dealCard() );
System.out.println();
System.out.println();
// Check if one of the players has Blackjack (two cards totaling to 21).
// The player with Blackjack wins the game. Dealer wins ties.
if (dealerHand.getBlackjackValue() == 21) {
System.out.println("Dealer has the " + dealerHand.getCard(0)
+ " and the " + dealerHand.getCard(1) + ".");
System.out.println("User has the " + userHand.getCard(0)
+ " and the " + userHand.getCard(1) + ".");
System.out.println();
System.out.println("Dealer has Blackjack. Dealer wins.");
return false;
}
if (userHand.getBlackjackValue() == 21) {
System.out.println("Dealer has the " + dealerHand.getCard(0)
+ " and the " + dealerHand.getCard(1) + ".");
System.out.println("User has the " + userHand.getCard(0)
+ " and the " + userHand.getCard(1) + ".");
System.out.println();
System.out.println("You have Blackjack. You win.");
return true;
}
// If neither player has Blackjack, play the game. First the user
// gets a chance to draw cards (i.e., to "Hit"). The while loop ends
// when the user chooses to "Stand". If the user goes over 21,
// the user loses immediately.
while (true) {
/* Display user's cards, and let user decide to Hit or Stand. */
System.out.println();
System.out.println();
System.out.println("Your cards are:");
for ( int i = 0; i < userHand.getCardCount(); i++ )
System.out.println(" " + userHand.getCard(i));
System.out.println("Your total is " + userHand.getBlackjackValue());
System.out.println();
System.out.println("Dealer is showing the " + dealerHand.getCard(0));
System.out.println();
System.out.println("Hit (H) or Stand (S)? ");
int userAction; // User's response, 'H' or 'S'.
do {
userAction = Character.toUpperCase( sc.nextChar() );
if (userAction != 'H' && userAction != 'S')
System.out.println("Please respond H or S: ");
} while (userAction != 'H' && userAction != 'S');
/* If the user Hits, the user gets a card. If the user Stands,
the loop ends (and it's the dealer's turn to draw cards).
*/
if ( userAction == 'S' ) {
// Loop ends; user is done taking cards.
break;
}
else { // userAction is 'H'. Give the user a card.
// If the user goes over 21, the user loses.
Card newCard = deck.dealCard();
userHand.addCard(newCard);
System.out.println();
System.out.println("User hits.");
System.out.println("Your card is the " + newCard);
System.out.println("Your total is now " + userHand.getBlackjackValue());
if (userHand.getBlackjackValue() > 21) {
System.out.println();
System.out.println("You busted by going over 21. You lose.");
System.out.println("Dealer's other card was the "
+ dealerHand.getCard(1));
return false;
}
}
} // end while loop
/* If we get to this point, the user has Stood with 21 or less. Now, it's
the dealer's chance to draw. Dealer draws cards until the dealer's
total is > 16. If dealer goes over 21, the dealer loses.
*/
System.out.println();
System.out.println("User stands.");
System.out.println("Dealer's cards are");
System.out.println(" " + dealerHand.getCard(0));
System.out.println(" " + dealerHand.getCard(1));
while (dealerHand.getBlackjackValue() <= 16) {
Card newCard = deck.dealCard();
System.out.println("Dealer hits and gets the " + newCard);
dealerHand.addCard(newCard);
if (dealerHand.getBlackjackValue() > 21) {
System.out.println();
System.out.println("Dealer busted by going over 21. You win.");
return true;
}
}
System.out.println("Dealer's total is " + dealerHand.getBlackjackValue());
/* If we get to this point, both players have 21 or less. We
can determine the winner by comparing the values of their hands. */
System.out.println();
if (dealerHand.getBlackjackValue() == userHand.getBlackjackValue()) {
System.out.println("Dealer wins on a tie. You lose.");
return false;
}
else if (dealerHand.getBlackjackValue() > userHand.getBlackjackValue()) {
System.out.println("Dealer wins, " + dealerHand.getBlackjackValue()
+ " points to " + userHand.getBlackjackValue() + ".");
return false;
}
else {
System.out.println("You win, " + userHand.getBlackjackValue()
+ " points to " + dealerHand.getBlackjackValue() + ".");
return true;
}
} // end playBlackjack()
} // end class BlackJackTest
- 03-25-2011, 07:25 AM #2
Use code tags to post codes -- [code]CODE[/code] will display as
dbJava Code:CODE
- 03-25-2011, 10:15 AM #3
keep cool. the cause of the errors is this line of code
private static nextChar();
first of all, local variables has no access modifier and i can't figure out what the line above is for, please exaplain.
Similar Threads
-
No more syntax error
By ideyatech in forum Java SoftwareReplies: 2Last Post: 04-22-2010, 04:20 AM -
stuck on same syntax error....
By Moltisanti in forum New To JavaReplies: 2Last Post: 09-01-2009, 04:26 AM -
how to solve syntax error
By pro85 in forum Java AppletsReplies: 5Last Post: 04-06-2009, 11:20 AM -
syntax error
By gabriel in forum New To JavaReplies: 3Last Post: 08-03-2007, 03:26 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks