title: Card trick Java
body: <p>I have been working on this program for over 30 hours and I am almost as lost now as when i first started. I've finally been able to print out 7 rows of 3 cards but i still have a few issues with my program. </p>
  
  <ol>
  <li><p>I need to have the cards line up on the word "of"</p></li>
  <li><p>when i call my PrintDeck() function it is supposed to print out all the cards in the deck but it does not.</p></li>
  <li><p>I cannot for the life of me figure out how to pick up the columns of cards in order to do the trick, If teh user chooses column 1 i'm supposed to pick it up second and then deal them out again in 7 rows of 3 columns. Then ask them to pick their card 2 more time and do the same thing.</p></li>
  </ol>
  
  <p>Any help you could offer would be greatly appreciated. I know some of the code is not very pretty but it has to be that way for the assignment in order for me to get credit :/ Thank you so much for all your help.</p>
  
  <p>instructions: here is a doc if the link works ----> <a href="http://word.office.live.com/wv/WordView.aspx?FBsrc=https://www.facebook.com/attachments/doc_preview.php?mid=id.376414855713455&amp;id=05ba139ea8f82045adb02272e74d6bf2&amp;metadata&amp;access_token=1850923532%3aAQBxvI0QdjuXTt48&amp;title=Cardtrick%20Instructions%20-%20Java" rel="nofollow">instructions doc</a>
  Program Requirements:</p>
  
  <p>Your program must generate its own random deck of cards using the following technique:</p>
  
  <ul>
  <li><p>generate a random integer for each card</p></li>
  <li><p>display a string value for each card ("Ace of Diamonds")</p></li>
  <li><p>use the rand() function to generate integer card values</p></li>
  <li><p>use the srand(time(0)) command (only once at the beginning of the program) to generate a truly random deck once the program has been tested and runs properly.</p></li>
  </ul>
  
  <p>Each value must be converted to the format  of  as done in the example above. Whenever your program displays the cards they must line up as they do above, on the word "of".<br>
  Your program must deal the cards out by row and pick them up by column (3 times to make it work properly).<br>
  Your program must ask the player is he/she wants to printout the entire deck before playing. Each card must be printed out formatted as above.<br>
  Your program must ask the player if he/she wants to play again, and continue playing as many times as the player wants.<br>
  The program must ask the player for his/her name and refer to the player by name throughout the playing of the game.<br>
  Your program code must be logically organized using functions. You also must use the starter file provided. You will GET A ZERO (0) if you do not use the starter file!  </p>
  
  <p>The starter file provided: CardtrickStarterFile.java if this pastes weird here is a pastebin link:  <a href="http://pastebin.com/rsZY2vKq" rel="nofollow">http://pastebin.com/rsZY2vKq</a></p>
  
  <pre><code>import java.util.Scanner;
  import java.lang.String;
  import java.util.Random;
  
  public class CardTrickStarterFile {
   private static Random rand = new Random();
   private static String PlayAgain;
  
  
  public static void main(String[] args) { 
  
  /* declare and initialize variables */
  int column = 0, i = 0;
  
  /* Declare a 52 element array of integers to be used as the deck of cards */
  int[] deck = new int[52];
  
  /* Declare a 7 by 3 array to receive the cards dealt to play the trick */
  int[][] play = new int[7][3];
  
  /* Declare a Scanner object for input */
  Scanner input = new Scanner(System.in);
  
  /* Generate a random seed for the random number generator. */
  
  
  
  /* Openning message.  Ask the player for his/her name */
  System.out.println("\nHello, I am a computer program that is so smart");
  System.out.println("I can even perform a card trick.  Here's how.\n");
  System.out.println("To begin the card trick type in your name: ");
   String name = input.nextLine();
  
   char firstL = name.charAt(0);
      firstL = Character.toUpperCase(firstL);
  
  name = replaceCharAt(name, 0, firstL);         
    /* Capitalize the first letter of the person's name. */
  
  
  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.println("the deck of cards looks like (y/n)? ");
  String SeeDeck = input.nextLine();
  
  switch (SeeDeck)
  {
      case "y":
          PrintDeck(deck);
      break;
      case "n":
          System.out.println("Ok then let us begin.");
          Deal(deck,play);
          break;
      default:
          break;
  }
  
  
  
  
  System.out.printf("\n%s, pick a card and remember it...\n", name);
  
  /* Begin the card trick loop */
  for(i = 0; i &lt; 3; i++)
  {
  /* Begin the trick by calling the function to deal out the first 21 cards */
  
  
  
  
  /* 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 &lt; 0 || column &gt; 2);
  
  /* Pick up the cards, by column, with the selected column second */
  
  
  
  }
  
  /* 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);
  String PlayAgain = input.nextLine(); 
  
  } 
  while(PlayAgain == "y");
  
  /* Exiting message */
  System.out.println("\nThank you for playing the card trick!\n");
  return;
  }
  
  public static String replaceCharAt(String s, int pos, char c) {
  return s.substring(0,pos) + c + s.substring(pos+1);
  }
  
  public static void BuildDeck( int deck[])
  {
  int[] used = new int[52];
  int i = 0;
  int card = 0;
  
  /* Generate cards until the deck is full of integers */
  while(i &lt; deck.length)
  {
      /* generate a random number between 0 and 51 */
  
      card = rand.nextInt(52);
      /* 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[card] == 0)
      {
                  used[card] = 1;
                  deck[i] = card;
                  i++;                
  
      }
  }
  
  }
  
  public static void PrintDeck( int deck[] )
  {
  
      for (int i=0; i &lt; 52; i++){
          PrintCard(i);
      }
  
  /* Print out each card in the deck */
  
  }
  
  public static void Deal( int deck[], int play[][] )
  {
  int 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("=======================================================");        
  
      for(int row = 0; row &lt; play.length; row++){
          for(int col = 0; col &lt; play[row].length; col++){               
              play[row][col]=deck[card];
             card++;
             System.out.printf("%s", PrintCard(play[row][col]) + "       ");
          } 
  
          System.out.println();
      }
  
  }
  
   public static String PrintCard( int card )
   {
     int rank = (card % 13);
     int suit = (card / 13);
     String[] suits = { "Clubs", "Hearts", "Diamonds", "Spades" }; 
     String[] ranks = { "King", "Ace", "2", "3", "4", "5", "6", 
       "7", "8", "9", "10", "Jack", "Queen"}; 
  
   return (ranks[rank] + " of " + suits[suit]); 
  
  }
  
  public static void PickUp( int deck[], int play[][], int column )
  {
   int card = 0, row = 0;
  
  
  
  
  
  
  
  
  return;
  }
  
  public static void SecretCard( int deck[] )
  {
  int card = 0;
  
  System.out.println("\nFinding secret card...");
  for(card = 0; card &lt; 10; card++)
      PrintCard(deck[card]);
  
  System.out.println("\nYour secret card is: ");
      PrintCard(deck[card]);
  return;
  }
  }
  </code></pre>