Results 1 to 6 of 6
  1. #1
    lauren is offline Member
    Join Date
    Dec 2015
    Posts
    5
    Rep Power
    0

    Default Need help with these errors ASAP!!!

    Hi guys I have my code for writing a program to play the card game war and I have these errors which I have no clue on and they're probably simple.
    HELP Thank you!! Errors are at very bottom after code

    Java Code:
    import javax.swing.*;
    import java.util.ArrayList;
    import java.awt.*;
    import java.awt.event.*;
    
    
    public class War 
    {
    	JFrame frame;
    	JPanel cardPanel, btnPanel;
    	JLabel statusBar;
    	
       //these are the labels that have the 
    	// 2 current card pictures for a round;
    	// as you play, these 2 card images change!
       JLabel lblPlayer1Card;
    	JLabel lblPlayer2Card;
    
    	ArrayList<Card> allCards = new ArrayList<Card>();
    	//each player has 2 decks: his current deck & his discard pile which has his winnings
    	ArrayList<Integer> player1Deck = new ArrayList<Integer>();
    	ArrayList<Integer> player1DiscardPile = new ArrayList<Integer>();
    	ArrayList<Integer> player2Deck = new ArrayList<Integer>();
    	ArrayList<Integer> player2DiscardPile = new ArrayList<Integer>();
       
    	//constructor
    	public War()
    	{
         frame = new JFrame();
    	  frame.setSize(500, 500);
    	  frame.setTitle("WAR");
    	  frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    	  frame.setLayout(new BorderLayout());
    	   
     	  cardPanel = new JPanel(new GridLayout(1,2));
         ///create labels and init with card back
    	  String strCard1 = "cardback.png";
    	  String strCard2 = "cardback.png";
    	  lblPlayer1Card = new JLabel(new ImageIcon(strCard1));
         lblPlayer2Card = new JLabel(new ImageIcon(strCard2));
    	  cardPanel.add(lblPlayer1Card);
    	  cardPanel.add(lblPlayer2Card);
    	
      //create a panel 
    	  btnPanel = new JPanel(new GridLayout(2,2));
    	  //set up next card button
    	  JButton btnNext = new JButton("Next Card");
    	  NextListener listener1 = new NextListener();
    	  btnNext.addActionListener(listener1);
    	  //set up new game button
    	  JButton btnNewGame = new JButton("New Game");
    	  NewGameListener listener2 = new NewGameListener();
    	  btnNewGame.addActionListener(listener2); 
    	   
    	  statusBar = new JLabel("");
         btnPanel.add(btnNext);
    	  btnPanel.add(btnNewGame);
    	  btnPanel.add(statusBar);
    	  
    	  frame.add(cardPanel, BorderLayout.CENTER);
    	  frame.add(btnPanel, BorderLayout.SOUTH);	
    	  frame.setVisible(true);
    
         //set up ALL CARDS DECK
    	  createAllCardsDeck();  //list of ALL cards
    
        //SET UP PLAYER'S INITIAL HANDS (26 cards each)
    	 initialDeal();
    	 	  
       }
    
      //this class handles button click on "next"
      class NextListener implements ActionListener
      {
         public void actionPerformed(ActionEvent e) 
         {
    	     Draw();
         }
      }
      //this class handles button click on "new game"  
      class NewGameListener implements ActionListener
      {
         public void actionPerformed(ActionEvent e) 
         {
    	     //restartGame();
         }
      }
    	
    	public void createAllCardsDeck()
    	{
    	   //create all 52 cards ; the player's decks
    		// will consist of indexes to this ALLCARDS deck
          allCards.add(new Card('c', 2, "c2.png"));
    		allCards.add(new Card('c', 3, "c3.png"));
    		allCards.add(new Card('c', 4, "c4.png"));
    		allCards.add(new Card('c', 5, "c5.png"));
    		//...DO THIS FOR THE REST OF THE 52 cards!!
    	}
    	
    	public void initialDeal()
    	{
    	
    		 //TEST CODE until initialDeal() works!
    	 player1Deck.add(0);
    	 player1Deck.add(2);
    	 player2Deck.add(1);
    	 player2Deck.add(3);
       /*  MAKE SOMETHING LIKE THIS WORK SO THAT YOU HAVE RANDOM CARDS IN EACH PLAYER's HAND   
    	  while (player1Deck.size() < 26)
    	  {
    	   	 //use Math.random to get a
    	     // random number between 0 and 51
    		 int randomNum = (int)(Math.random() * 51);   
    		 if (!player1Deck.contains(randomNum))
    		  {
    		     player1Deck.add(randomNum);
    		  }
    	  } 
    	 
    	  while (player2Deck.size() < 26)
    	  {
    	   	 //use Math.random to get a
    	     // random number between 0 and 51
    		 int randomNum = (int)(Math.random() * 51);   
    		 if (!player2Deck.contains(randomNum))
    		  {
    		     player2Deck.add(randomNum);
    		  }
    	  } 
        */
    	 
    	 //test to make sure both decks should have 26 cards after you are done!
    	 //System.out.println("size of deck1 = " + player1Deck.size());
    		// System.out.println("size of deck2 = " + player2Deck.size());
    
    	}
    
    
    /*********************************************/
    /* Draw() -- each player draws a card from
    /*           the top of his deck
    /*********************************************/	
    	public void Draw()
    	{
    	  boolean bDone = false;
    
        //CHECK IF GAME IS OVER FIRST!
        if (player1Deck.isEmpty())
    		 {
    		   if (player1DiscardPile.isEmpty())
    			 {
    			   bDone = true;
    				statusBar.setText(" PLAYER 1 LOST ; PLAYER 2 WON");
    			  }	
    		   else  //put the discard cards into the player1 deck & restart
    			  Shuffle(player1Deck, player1DiscardPile);		
    		 }
    		 
    		 	if (player2Deck.isEmpty())
    		 {
    		   if (player2DiscardPile.isEmpty())
    			 {
    			   bDone = true;
    				statusBar.setText("PLAYER 2 LOST ; PLAYER 1 WON");
    			  }	
    		   else  //put the discard cards into the player1 deck & restart
    			  Shuffle(player2Deck, player2DiscardPile);		
    		 }
    		 
    		 if (!bDone)
    		 {
    		 
    		 		 
    	   //get 1st card("card on top") from player 1's deck array
    	    int idxCard1 = player1Deck.get(0);//index of card
    		 Card player1Card = allCards.get(idxCard1);
    //		 System.out.println("player 1 card idx = " + idxCard1 
    //		   + " val=" + player1Card.getCardValue());
    //		 System.out.println("card str = " + player1Card.getCardString()); 
    		 
    		 lblPlayer1Card.setIcon(new ImageIcon(player1Card.getCardString()));
    		 
    		//get 1st card("card on top") from player 2's deck array 
    		 int idxCard2 = player2Deck.get(0);//index of card
    		 Card player2Card = allCards.get(idxCard2);
    //		 System.out.println("player 2 card idx = " + idxCard2 
    //		   + " val=" + player2Card.getCardValue());
    //		 System.out.println("card str = " + player2Card.getCardString()); 
    	 		 	 
    	    lblPlayer2Card.setIcon(new ImageIcon(player2Card.getCardString())); 
    		 
    		 cardPanel.revalidate();
    
         //COMPARE 2 cards
    	  //compare player1Card.getValue() to player2Card.getValue()
    	  if (player1Card.getCardValue() > player2Card.getCardValue())
    	  {
    	    //player 1 won so add both player 1 and player 2 cards to player 1's discard pile
    	    player1DiscardPile.add(idxCard1);
    		 player1DiscardPile.add(idxCard2);
    		 //take the top card away from both their playing decks
    		 player1Deck.remove(0);
    		 player2Deck.remove(0);
    	  }
    	  else if (player2Card.getCardValue() > player1Card.getCardValue())
    	  {
    	  	    //player 2 won so add both player 1 and player 2 card to player 2's discard pile
    
    	  	    player2DiscardPile.add(idxCard1);
    		 player2DiscardPile.add(idxCard2);
    		 //take the top card away from both their playing decks
    		 player1Deck.remove(0);
    		 player2Deck.remove(0);
    	  }
    	  else //player1Card.getCardValue() == player2Card.getCardValue()
    	  {
    	     //playWAR();
    	  }
    	  
            }//if not done
    
    	}
    	
    	public void Shuffle(ArrayList<Integer> deck1, ArrayList<Integer> deck2)
    	{
    	   //mix up or shuffle the cards in deck2 and put them in deck1 which is empty..
    		// it will be returned back to the method that called this method.
    	}
    	
    	//WRITE THE CODE TO PLAY WAR ...
    	//each player ignores the next 3 cards (W-A-R) 
    	// and uses the 4th card to compare against their opponent's card 
    	public void playWAR()
    	{
       }
    	
    }

    War.java:25: error: cannot find symbol
    ArrayList<Card> allCards = new ArrayList<Card>();
    ^
    symbol: class Card
    location: class War
    War.java:25: error: cannot find symbol
    ArrayList<Card> allCards = new ArrayList<Card>();
    ^
    symbol: class Card
    location: class War
    War.java:99: error: cannot find symbol
    allCards.add(new Card('c', 2, "c2.png"));
    ^
    symbol: class Card
    location: class War
    War.java:100: error: cannot find symbol
    allCards.add(new Card('c', 3, "c3.png"));
    ^
    symbol: class Card
    location: class War
    War.java:101: error: cannot find symbol
    allCards.add(new Card('c', 4, "c4.png"));
    ^
    symbol: class Card
    location: class War
    War.java:102: error: cannot find symbol
    allCards.add(new Card('c', 5, "c5.png"));
    ^
    symbol: class Card
    location: class War
    War.java:182: error: cannot find symbol
    Card player1Card = allCards.get(idxCard1);
    ^
    symbol: class Card
    location: class War
    War.java:191: error: cannot find symbol
    Card player2Card = allCards.get(idxCard2);
    ^
    symbol: class Card
    location: class War
    8 errors

  2. #2
    SurfMan's Avatar
    SurfMan is offline Godlike
    Join Date
    Nov 2012
    Location
    The Netherlands
    Posts
    1,995
    Rep Power
    9

    Default Re: Need help with these errors ASAP!!!

    The errors you have posted DO NOT correspond with the code you are showing:
    War.java:25: error: cannot find symbol
    This line is empty in your code.

    It looks like the compiler can't find the Card class.

    Edit: Oh, and go easy on the ASAP. As long as you're not paying me to solve your problems, you are not in charge of my time.
    "It's not fixed until you stop calling the problem weird and you understand what was wrong." - gimbal2 2013

  3. #3
    benji2505 is offline Senior Member
    Join Date
    Sep 2014
    Location
    MA, USA
    Posts
    399
    Rep Power
    7

    Default Re: Need help with these errors ASAP!!!

    put lines 37-40 above in a try-catch statement and see whether it gives you an IO error.

    Edit: ASAP.

  4. #4
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    14,422
    Blog Entries
    7
    Rep Power
    28

    Default Re: Need help with these errors ASAP!!!

    Quote Originally Posted by benji2505 View Post
    put lines 37-40 above in a try-catch statement and see whether it gives you an IO error.

    Edit: ASAP.
    Nah, the code doesn't even compile ...

    kind regards,

    Jos

    ps. I replied ASAP but I was a bit busy, sorry for that ...
    Build a wall around Donald Trump; I'll pay for it.

  5. #5
    benji2505 is offline Senior Member
    Join Date
    Sep 2014
    Location
    MA, USA
    Posts
    399
    Rep Power
    7

    Default Re: Need help with these errors ASAP!!!

    In all the haste I could not find the card class. The problem might be in that class.

  6. #6
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    6,226
    Rep Power
    14

    Default Re: Need help with these errors ASAP!!!

    How can you possibly keep track of things in this code? You should take the time to properly indent and align your braces {} and statements.

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

Similar Threads

  1. I need help asap!
    By Kurtesy in forum New To Java
    Replies: 4
    Last Post: 06-24-2013, 07:35 PM
  2. Please Help ASAP!
    By PleaseHelp in forum New To Java
    Replies: 5
    Last Post: 04-24-2012, 02:25 PM
  3. Please need help asap
    By Tamtome in forum New To Java
    Replies: 9
    Last Post: 02-04-2011, 08:19 PM
  4. Replies: 4
    Last Post: 01-04-2011, 12:36 AM
  5. Replies: 3
    Last Post: 03-08-2009, 01:51 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •