Results 1 to 5 of 5
  1. #1
    Addez is offline Senior Member
    Join Date
    Aug 2009
    Rep Power

    Cool Cannot find symbol variable yourScore

    Im kinda new to java so I got problems in prittie much everything I do.
    So my problem is that I get: Cannot find symbol variable (or method) method/variable;name
    So I get this error on the following:

    You see? I suck at java!
    I'v tried everything! Doing the class public just makes more errors.
    trying to do this.yourScore for example didnt work either.
    NOTHING works..

    Can someone explain what im doing wrong?

    Heres the code:
    PHP Code:
     * @(#)
     * Blackjack application
     * @Andreas
     * @version 1.00 2009/8/14
     import static java.lang.System.out;
     import java.util.Scanner;
     import java.util.Random;
     class cardTypes {
     	static String takencards[] = new String[56];
     	public static void main(String[] args){
    		for (int x = 0; x <57; x++) {
    			takencards[x] = "Nothing";
     	enum types {Harts, Diamonds, Spads, Clover};
     	enum types2 {One, Two, Three, Four, Five, Six, Seven, Eight, Nine, Ten, Jack, Queen, King, Ace};
    class values {
      	static int yourScore = 0;
     	static int dealersScore = 0;
    	public static int getYourScore(){
        	return yourScore;
    	public static int getDealersScore(){
        	return values.dealersScore;
    	public static void setDealerScore(int v){
        	dealersScore = dealersScore+v;
    	public static void setYourScore(int v){
        	yourScore = yourScore+v;
    public class Blackjack {
        public static void main(String[] args) {
        	Random numbGen = new Random();
        	// TODO, add your application code
        	out.println("Wellcome to blackjack!");
        	String mykey;
        	int arrayNumber = 0;
        	Scanner key = new Scanner(;
        	do {
        	out.println("Press enter to start!");
        	mykey = key.nextLine();
        	}while (!mykey.equals(""));
        	Scanner cont = new Scanner(;
        	char reply = 'a';
    		do {
    			boolean d = false;
        		String card = getUntakenCard(arrayNumber,numbGen,d);
    			arrayNumber = arrayNumber+1;
    			out.println("You got the card: "+card);
    			out.println("Your current score is: "+values.getYourScore());
    			d = true;
        		card = getUntakenCard(arrayNumber,numbGen,d);
    			arrayNumber = arrayNumber+1;
    			out.println("The dealer got the card: "+card);
    			out.println("The dealers score is: "+values.getDealerScore());
    			if (values.getYourScore() > 21) {
    			do {
    				System.out.println("Continue? (y/n)");
    				reply = cont.findWithinHorizon(".",0).charAt(0);
    				mykey = cont.nextLine();
        		} while (reply != 'y' && reply != 'n' && mykey.equals("") );			
    			card = null;
    		}while (reply == 'y');
    			if (values.getYourScore() < 22 && values.getYourScore() >values.getDealersScore()){
    				out.println("Your score was: "+values.getYourScore());
    				out.println("The dealer had: "+values.getDealersScore());
    				out.println("YOU WON!");
    			if (values.getYourScore() > 21 || values.getYourScore() <= values.getDealersScore()) {
    				out.println("Your score was: "+values.getYourScore());
    				out.println("GAME OVER");	
        static String getUntakenCard(int arrayNumber, Random numbGen,boolean d){
        	String card;
        	Boolean found = true;
    			card = new Blackjack().getRandomCard(numbGen,d);
    			found = false;
    			for (int tc = 0; tc<56; tc++){
    				if (cardTypes.takencards[tc] != null){
    					if (cardTypes.takencards[tc].equals(card)){
    						found = true;
        	} while (found == true);
    			//System.out.println("ArrayNumber: "+arrayNumber);
    			cardTypes.takencards[arrayNumber] = card;
        	return card;    	
        String getRandomCard(Random numbGen,boolean d){
        	int n = numbGen.nextInt(4);
    		cardTypes.types[] values = cardTypes.types.values(); // this static method will get an array of 'e'
    		cardTypes.types eVal = values[n];
    		int n2 = numbGen.nextInt(14);
    		cardTypes.types2[] values2 = cardTypes.types2.values(); // this static method will get an array of 'e'
    		cardTypes.types2 eVal2 = values2[n2];
    		yourScore = yourScore + n2;
    			if (d == false){
    			if (d == true){
    		return eVal2+" of "+eVal;

  2. #2
    Spiller is offline Member
    Join Date
    Aug 2009
    Rep Power


    Few different problems:

    In your values class, getDealersScore should be getDealerScore.

    In your getRandomCard function, you have a variable declaration (cardTypes.types[] values) which is hiding access to the values class, then it thinks you're trying to call functions on that array. If you start class names with upper case letters as per convention, or simply rename one or the other of them, it would avoid this.

    The "yourScore = yourScore + n2;" line looks left-over / redundant to the method calls below it, or else it needs to be qualified with "values." in front of it.

  3. #3
    Addez is offline Senior Member
    Join Date
    Aug 2009
    Rep Power


    1. change name to getDealerScore?
    If I would do that my whole code would crash since everyone is calling for
    getDealersScore() not Dealer.
    2. Can you explain some more of how the class with the enums connects with the value class? Cause you said something about hidden connection and Idk what that is...
    3. OPS, yea its a leftover

  4. #4
    Addez is offline Senior Member
    Join Date
    Aug 2009
    Rep Power


    I really dont understand cause values.getDealersScore should execut tthat function, but somehow it cant find it.
    And the name is not wrong Iv even copy pasted it.
    I think I should like put static or public or any of those prefixes somewhere but Idk where...

  5. #5
    Addez is offline Senior Member
    Join Date
    Aug 2009
    Rep Power


    Thank you soo much!!
    The problem was as you said the values didnt reffer to the values class but to something else, Thanks so much! Now its all working!

Similar Threads

  1. cannot find symbol
    By GabWit in forum New To Java
    Replies: 3
    Last Post: 01-25-2009, 01:13 AM
  2. java:34:cannot find symbol
    By MissyMadi in forum New To Java
    Replies: 5
    Last Post: 11-09-2008, 07:53 PM
  3. Replies: 9
    Last Post: 10-18-2008, 09:26 PM
  4. Replies: 3
    Last Post: 05-01-2008, 09:30 AM
  5. Error: cannot find symbol
    By cachi in forum AWT / Swing
    Replies: 1
    Last Post: 08-06-2007, 09:12 PM

Tags for this Thread

Posting Permissions

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