Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 14 of 14

Thread: Card Trick Program: Error Message

  1. #1
    Junior Member
    Join Date
    Oct 2013
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Card Trick Program: Error Message

    */
    import java.util.Scanner;
    import java.util.Random;
     
    public class CardTrick {
         public static void main(String[] args) {
     
        /* declare and initialize variables */
        int column = 0, i = 0;
        String name = " ";
        String playAgain = " ";
        String seeDeck = " ";
     
        /* Declare a 52 element array of cards */
            Card[] deck = new Card [52];
     
        /* Declare a 7 by 3 array to receive the cards dealt to play the trick */
            Card [][] play = new Card[7][3];
     
        /* Declare a Scanner object for input */
        Scanner input = new Scanner(System.in);
     
        /* Openning message.  Ask the player for his/her name */
        System.out.println("\nHello, I am a very talented computer program and");
        System.out.println("I can even perform a card trick.  Just watch and be amazed.\n");
        System.out.print("To begin the card trick type in your first name: ");
        name = input.nextLine();
     
        /* Capitalize the first letter of the person's name. */
        name = name.substring(0,1).toUpperCase() + name.substring(1);
     
        System.out.println("\nThank you " + name);
     
        do
        {
            /* Build the deck */
            BuildDeck(deck);
     
            /* Ask if the player wants to see the entire deck. If so, print it out. */
            System.out.println("Ok " + name + ", first things first.  Do you want to see what ");
            System.out.print("the deck of cards looks like (y/n)? ");
            seeDeck = input.next();
     
     
            System.out.printf("\n%s, pick a card and remember it...\n", name);
     
            /* Begin the card trick loop */
            for(i = 0; i < 3; i++)
            {
                /* Begin the trick by calling the method to deal out the first 21 cards */
                    Deal (deck, play);
     
                /* Include error checking for entering which column */
                do
                {
    				/* Ask the player to pick a card and identify the column where the card is */
    				System.out.print("\nWhich column is your card in (0, 1, or 2)?: ");
    				column = input.nextInt();
                } while(column < 0 || column > 2);
     
                /* Pick up the cards, by column, with the selected column second */
                    PickUp(deck, play, column);
            }
     
            /* Display the top ten cards, then reveal the secret card */
     
     
            /* if the player wants to play again */
            System.out.printf("%s, would you like to play again (y/n)? ", name);
            playAgain = input.next();
        } while(playAgain.equals("y"));
     
        /* Exiting message */
        System.out.print("\n\nThank you for playing the card trick!\n");
    }
     
    public static void BuildDeck( Card deck[])
    {
        int [][] used = new int[13][4];
        int rank = 0, suit = 0, i = 0;
     
        Random rand = new Random();
     
        /* Generate cards until the deck is full of cards */
        while(i < deck.length)
        {
     
    		/* generate a random number between 0 and 12 for rank */
                    rank = rand.nextInt(13);
     
    		/* generate another random number between 0 and 3 for suit */
                    suit = rand.nextInt(4);
     
    		/* Check the used array at the position of the card.
    		   If 0, add the card and set the used location to 1.  If 1, generate another number */
     
    		if (used[rank][suit] == 0)
                    {
                        used[rank][suit] = 1;
                        deck[i] = new Card(rank, suit);
                        i++;
     
                    }
        }
    }
     
    public static void PrintDeck( Card deck[] )
    {
     
        /* Print out each card in the deck */
        for (int i = 0; i< deck.length; i++){
     
        System.out.println(deck[i].toString());
        } 
    }
     
    public static void Deal( Card deck[], Card play[][] )
    {
        int row = 0, col = 0, card = 0;
     
     
        /* deal cards by passing addresses of cardvalues from
           the deck array to the play array                   */
        System.out.println("\n   Column 0           Column 1           Column 2");
        System.out.println("=======================================================\n");
     
        for (row = 0; row < 7; row++){
     
            for (col = 0; col < 3; col++){
               play[row][col] = deck[card];
               System.out.print(deck[card].toString());
               card++;
     
            }
            System.out.println();
        }
     
     
     public static void PickUp( Card deck[], Card play[][], int column )
    {
        int card = 0, row = 0, first = 0, last = 0;
     
    switch(column)
    {
            case 0:
    	first = 1;
    	last = 2;
    	break;
     
            case 1:
    	first = 2;
    	last = 0;
    	break;
     
            case 2:
    	first = 1;
    	last = 0;
    	break;
    }
     
    for(row = 0; row < 7; row++)
    {
    	deck [card] = play [row][first];
    	card++;
     
    }
     
    for(row = 0; row < 7; row++)
    {
    	deck [card] = play [row][column];
    	card++;
     
    }
     
    for(row = 0; row < 7; row++)
    {
    	deck [card] = play [row][last];
    	card++;
     
    }
     
     
     
     
    }
     
    public static void SecretCard( Card deck[] )
    {
        int card;
     
        System.out.println("\nFinding secret card...");
        for(card = 0; card < 10; card++)
        	System.out.printf("%s \n", deck[card].toString());
     
        System.out.printf("\nYour secret card is: %s \n", deck[card].toString());
     
        }
     
        private static class card {
     
            public card() {
            }
        }
    }


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Card Trick Program: Error Message

    Did you have a question?

    Please edit your post and wrap your code with code tags:
    [code=java]
    YOUR CODE HERE
    [/code]
    to get highlighting and preserve formatting.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Oct 2013
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Card Trick Program: Error Message

    I am getting an error that says "illegal start of expression" in line 149 at the start of PickUp method. I dont know why.

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Card Trick Program: Error Message

    Hard to see the logic and structure of the code when it is not properly formatted.

    Where in the error message is the ^ located?
    You should copy the full text of the error message and post it, not just part of one line of the message.
    A sample:
    The message should show the source with a ^ under the location of the error.
    Here is a sample from the javac compiler:
    TestSorts.java:138: cannot find symbol
    symbol  : variable var
    location: class TestSorts
             var = 2;
             ^
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Junior Member
    Join Date
    Oct 2013
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Card Trick Program: Error Message

    I fixed it! Would you happen to know why I am getting an error at the start of my PickUp method?

  6. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Card Trick Program: Error Message

    Sorry, I can't see your computer's console from here. You will have to post the message. See post#4
    If you don't understand my answer, don't ignore it, ask a question.

  7. #7
    Junior Member
    Join Date
    Oct 2013
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Card Trick Program: Error Message

    Exception in thread "main" java.lang.RuntimeException: Uncompilable source code - illegal start of expression
    at CardTrick.Deal(CardTrick.java:149)
     
    	at CardTrick.main(CardTrick.java:59)

  8. #8
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Card Trick Program: Error Message

    Where is the ^ that points to the error's location in the statement.

    IDEs are very poor at posting compiler errors. What you posted was not from the javac compiler. See post#4 for a sample.

    illegal start of expression
    That error is often because of misplaced {}s.
    If you don't understand my answer, don't ignore it, ask a question.

  9. #9
    Junior Member
    Join Date
    Oct 2013
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Card Trick Program: Error Message

    I'm fairly new to programming in java, how do I locate the javac compiler? Is it in the program NetBeans?

  10. #10
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Card Trick Program: Error Message

    The javac program is in the JDK's bin folder.
    If you don't understand my answer, don't ignore it, ask a question.

  11. #11
    Junior Member
    Join Date
    Oct 2013
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Card Trick Program: Error Message

    I have no idea where to find that. I appreciate your time, thanks!

  12. #12
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Card Trick Program: Error Message

    Sorry, I can't help much. In have no idea what products you have installed on your computer or how to find the ones that are installed.

    Can you ask your IDE for some more information about the problem?

    Did you check that the code's {}s were properly located?
    If you don't understand my answer, don't ignore it, ask a question.

  13. #13
    Junior Member
    Join Date
    Oct 2013
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Card Trick Program: Error Message

    Created dir: /Users/madisonhenline/NetBeansProjects/CardTrick1/dist/javadoc
    Warning: Leaving out empty argument '-windowtitle'
    /Users/madisonhenline/NetBeansProjects/CardTrick1/nbproject/build-impl.xml:1206: No source files and no packages have been specified.
    BUILD FAILED (total time: 0 seconds)

    Would this help?

  14. #14
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Card Trick Program: Error Message

    Sorry, I do not recognize any of that.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Need help with error message!!
    By Rick Sebastian in forum What's Wrong With My Code?
    Replies: 14
    Last Post: March 25th, 2013, 10:24 AM
  2. Card shuffle program
    By Grot in forum What's Wrong With My Code?
    Replies: 6
    Last Post: March 10th, 2013, 01:24 PM
  3. [SOLVED] Program is running successfully but still getting error message..
    By sumit043020701 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: December 24th, 2011, 12:26 AM
  4. How to make an error message when my program crashes?
    By noFear in forum Java Theory & Questions
    Replies: 10
    Last Post: August 11th, 2010, 08:50 AM
  5. help with a error message
    By JavaNoob82 in forum What's Wrong With My Code?
    Replies: 6
    Last Post: January 23rd, 2010, 02:56 PM