4 Replies - 262 Views - Last Post: 14 November 2012 - 03:00 PM Rate Topic: -----

#1 bobjenkins12  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 03-November 12

Does anyone know why i'm getting these errors in my program?

Posted 14 November 2012 - 02:40 PM

Okay so im getting a couple of errors in my program and i can't figure out how to solve them. If you can help it will be much appreciated
These are the errors i'm getting:

SolitaireEncrypt.java:6: cannot find symbol
symbol : class CardDeck
location: class SolitaireEncrypt
private CardDeck deck;
^
SolitaireEncrypt.java:44: cannot find symbol
symbol : class CardDeck
location: class SolitaireEncrypt
deck = new CardDeck(deckString);
^
SolitaireEncrypt.java:131: cannot find symbol
symbol : variable CardDeck
location: class SolitaireEncrypt
if (i == CardDeck.FIRSTJOKER || i == CardDeck.SECONDJOKER) {
^
SolitaireEncrypt.java:131: cannot find symbol
symbol : variable CardDeck
location: class SolitaireEncrypt
if (i == CardDeck.FIRSTJOKER || i == CardDeck.SECONDJOKER) {
^
SolitaireEncrypt.java:202: cannot find symbol
symbol : class Card
location: class SolitaireEncrypt
Card theCard = deck.getCardAt(cardPos);
^

Heres my code:


import java.io.*;
import java.util.*;

public class SolitaireEncrypt
{
    private CardDeck deck;
    

    public static final int DECRYPT = 0;
    public static final int ENCRYPT = 1;
    public static final int MODEPROMPT = 2;
	
   
    public static boolean DOSANITYCHECKS = false;
	
    
    private static int iterations = 0;
	
        private void go(String deckFilename, int encryptOrDecrypt)
    {
        Scanner keyboard = new Scanner(System.in);
	String deckString = "";
		
        if (deckFilename.equals("-"))
	{
        
            System.out.print("Enter deck: ");
            deckString = keyboard.nextLine();
	} else {
            try {
                FileReader fr = new FileReader(deckFilename);
                BufferedReader br = new BufferedReader(fr);
                deckString = br.readLine();
                fr.close();
            } catch (FileNotFoundException ex) {
                System.err.println("File not found!");
                System.exit(1);
            } catch (IOException ex) {
                System.err.println("I/O error!");
                System.exit(2);
            }
	}
		
        deck = new CardDeck(deckString);

     

        String input = "";
		
        while (encryptOrDecrypt == MODEPROMPT) {
            System.out.print("(E)ncrypt or (D)ecrypt? ");
            String response = keyboard.nextLine();
            response = response.toLowerCase();
            if (response.equals("e") || response.equals("encrypt")) {
                encryptOrDecrypt = ENCRYPT;
            } else if (response.equals("d") || response.equals("decrypt")) {
                encryptOrDecrypt = DECRYPT;
            } else {
                System.out.println("That's not a valid response.");
            }
        }		
		
        if (encryptOrDecrypt == ENCRYPT)
            System.out.print("Enter text (XXXXX to quit): ");
        else
            System.out.print("Enter encrypted text (XXXXX to quit): ");
 
        while (!(input = keyboard.nextLine()).equals("XXXXX")) {
            if (input.length() % 5 != 0 && encryptOrDecrypt == DECRYPT)
                System.err.println("WARNING: This message may be corrupt!\n");
            
            if (encryptOrDecrypt == ENCRYPT) {
                System.out.println(encrypt(input));
                System.out.print("Enter text (XXXXX to quit): ");
            } else {
                System.out.println(decrypt(input));
                System.out.print("Enter encrypted text (XXXXX to quit): ");
            }
        }
        
        System.out.println("Bye!");
	
    }
	
    
    public String decrypt(String encrypted)
    {
        Integer[] ints = stringToInts(encrypted);
        
        for (int i = 0; i < ints.length; i++) {
            int key = getNextKey();
            ints[i] -= key;
            if (ints[i] < 1)
                ints[i] += 26;
            }
		
        return intsToString(ints);
    }
	
  
    public String encrypt(String plain)
    {
        Integer[] ints = stringToInts(plain);
		
        for (int i = 0; i < ints.length; i++) {
            int key = getNextKey();
            ints[i] += key;
            if (ints[i] > 26)
                ints[i] -= 26;
        }
		
        return intsToString(ints);
    }
	
   
    public int getNextKey()
    {
    	iterations++;
    	
        stepOne();  
        doSanityCheck("one");
        stepTwo();    
        doSanityCheck("two");
        stepThree(); 
        doSanityCheck("three");
        stepFour();  
        doSanityCheck("four");
        
        int i = stepFive(); 
        
        if (i == CardDeck.FIRSTJOKER || i == CardDeck.SECONDJOKER) {
            return getNextKey();
        } else {
            return i;
        }
    }
    
    
    private void doSanityCheck(String step)
    {
        if (DOSANITYCHECKS) {
            String badness = deck.sanityCheck();
            if (!badness.equals("")) {
                System.err.println("Oops! Deck got messed up on iteration "
                        + iterations +" after step " + step + ":\n" + badness
                        + "\nExiting!");
                System.exit(-2);
            }
        }
    }
    
 
    public void runTest(int howMany)
    {
    	boolean oldCheckStatus = DOSANITYCHECKS;	
    	DOSANITYCHECKS = true;
    	
    	System.out.printf("TESTING: generating %,d keys:\n", howMany);
    	
    	long stime = System.currentTimeMillis();
    	
    	for (int i = 0; i < howMany; i++) {
    	    System.out.printf("%,d:\t%d\n", i + 1, getNextKey());
        }
		
    	long etime = System.currentTimeMillis();
    	System.out.printf("Time: %.3f seconds.\n",
    	        (float) (etime - stime) / 1000);

    	DOSANITYCHECKS = oldCheckStatus;	
    }
    
    public void stepOne()
    {
        deck.firstJokerSwapNext();
    }
    
    public void stepTwo()
    {
        deck.secondJokerSwapNextTwice();
    }
    
    public void stepThree()
    {
        deck.tripleCut();
    }
    
    public void stepFour()
    {
        deck.countCut();
    }
    
    public int stepFive()
    {
        int cardPos;
    	if (deck.getHead() == deck.getSecondJoker()) {
    	    cardPos = deck.getFirstJoker().getDatum();
    	} else {
    	    cardPos = deck.getHead().getDatum();
    	}
    	
    	Card theCard = deck.getCardAt(cardPos); 
    	return theCard.getDatum();
    }
    
  
    public Integer[] stringToInts(String s)
    {
    	char[] ca = s.toCharArray();
    	ArrayList<Integer> list = new ArrayList<Integer>();
    	
    	for (int i = 0; i < ca.length; i++) {
    	    if (ca[i] < 65 || (ca[i] > 90 && ca[i] < 97) || ca[i] > 122)
    	        continue; 
    		
    	    if (ca[i] >= 97 && ca[i] <= 122)
    	        ca[i] -= 32; 
    		
    	    ca[i] -= 64; 
    		
    	    list.add((int) ca[i]);
    	}
    	
    	for (int i = 0; i < list.size() % 5; i++)
    	    list.add(((int) 'X') - 64); 
    	
    	return list.toArray(new Integer[] {});
    }
    
    
    public String intsToString(Integer[] ints)
    {
    	StringBuffer buf = new StringBuffer();
    	
    	for (int i = 0; i < ints.length; i++) {
        
    	    buf.append((char) (ints[i].intValue() + 64));
    	}
    	
    	return buf.toString();
    }		
	
  
    public static void main(String[] args)
    {
        SolitaireEncrypt app = new SolitaireEncrypt();
		
        if (args.length == 0) {
            args = new String[2];
            args[0] = "-";
            args[1] = "ask";
        }
		
        int enc_dec;
        if (args.length >= 2 && args[1].equals("encrypt")) {
            enc_dec = ENCRYPT;
        } else if (args.length >= 2 && args[1].equals("ask")) {
            enc_dec = MODEPROMPT;
        } else {
            enc_dec = DECRYPT;
        }
		
        app.go(args[0], enc_dec);
    }
}




Is This A Good Question/Topic? 0
  • +

Replies To: Does anyone know why i'm getting these errors in my program?

#2 GregBrannon  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2203
  • View blog
  • Posts: 5,235
  • Joined: 10-September 10

Re: Does anyone know why i'm getting these errors in my program?

Posted 14 November 2012 - 02:44 PM

What/where is the class CardDeck? Apparently, the compiler can't find it either.
Was This Post Helpful? 0
  • +
  • -

#3 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8342
  • View blog
  • Posts: 31,880
  • Joined: 06-March 08

Re: Does anyone know why i'm getting these errors in my program?

Posted 14 November 2012 - 02:44 PM

here is your class CardDeck declared ?
The file CardDeck.java and CardDeck.class are they in the same directory as SolitaireEncrypt.java and SolitaireEncrypt.class ?
Was This Post Helpful? 0
  • +
  • -

#4 bobjenkins12  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 03-November 12

Re: Does anyone know why i'm getting these errors in my program?

Posted 14 November 2012 - 02:54 PM

Okay thanks i got it. is there anything i can do that will allow the program to run without having CARDDECK.java or CARDDECK.class?
Was This Post Helpful? 0
  • +
  • -

#5 GregBrannon  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2203
  • View blog
  • Posts: 5,235
  • Joined: 10-September 10

Re: Does anyone know why i'm getting these errors in my program?

Posted 14 November 2012 - 03:00 PM

First, it's CardDeck. Java is case sensitive.

That class defines what a deck of cards is (to your program), including the methods needed to do card deck behaviors. To get rid of it, rewrite all CardDeck methods in your current code and eliminate any reference to it.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1