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);
}
}

New Topic/Question
Reply



MultiQuote



|