• June 1st, 2012, 05:06 PM
drewgangsta
Need help with my cryptogram program,
the program skips over the line of code that asks for the letter you need to replace
Thank you so much

import Keyboard.*;
import java.io.*;
import java.util.*;
import java.text.*;
import java.util.Arrays;
/**
* Write a description of class SolveCryptogram here.
*
* @author Matthew Campbell
* @version 6-01-12
*/
public class SolveCryptogram
{
static final int LETTERS_IN_ALPHABET = 25;
public static void main(String args[])
throws java.io.IOException, java.text.ParseException
{
String message;
char selection, letter, replacement;
char check = 'y';

char[] messageone; //original cryptogram
char[] substitution1 = new char[LETTERS_IN_ALPHABET]; //letter from original cryptogram that you want to change
char[] substitution2 = new char[LETTERS_IN_ALPHABET]; //letter that it will change to
char[] messagetwo = new char [4096]; //decoded message
int subsMade = 0; //keeps track of how many substitutions you've made, slightly archaic in this build.
System.out.println("--- Cryptogram Helper ---");
message = message.toLowerCase(); //prevents case conflicts
messageone = message.toCharArray(); //stores the original cryptogram as a char instead of a string
for(int q = 0; q < messageone.length; q++){
if (Character.isWhitespace(messageone[q])){
messageone[q] = '.'; //meant to handle spaces in the substitutions.
}
}
selection = Keyboard.readChar("(R)eplace letter or (Q)uit: ");
selection = Character.toLowerCase(selection); //prevents case conflicts
switch (selection)
{
case 'r':
System.out.println("Do not replace periods in your cryptogram."); //periods indicate spaces, this is why they're ignored
for(int i = 0; i <= LETTERS_IN_ALPHABET; i++){
letter = Character.toLowerCase(Keyboard.readChar("Letter from cryptogram: "));
substitution1[i] = letter;
System.out.println();
substitution2[i] = replacement;
check = Keyboard.readChar("Make another substitution? (y/n) ");
check = Character.toLowerCase(check); //prevent case conflicts
if (check == 'y'){
i = i; //a type of do nothing
}
else{
substitution1[(i+1)] = '.';
substitution2[(i+1)] = ' '; //replaces periods into spaces
i = 30; //forces an exit out of the loop
}
}
System.out.println("Making substitutions...");
for(int l = 0; l <= message.length() - 1; l++){
int o = 0; //used to spider the substitution1 array for replacements
while(substitution1[o] != messageone[l]){
o++;
}
messagetwo[l] = substitution2[o];
System.out.println("Substituted " + substitution1[o] + " with " + substitution2[o]); //keeps track of replacements made for the user

}
System.out.println("");
for(int gh = 0; gh <= message.length() - 1; gh++){
System.out.print(messagetwo[gh]); //displays the decoded message
}
break;

case 'q':
break;
}
}
}
• June 1st, 2012, 05:09 PM
drewgangsta
The project guidlines are
Enter cryptogram: ABC

(R)eplace letter or (Q)uit: r
Letter from cryptogram: A
Replace with: B

Original cryptogram: ABC
With replacements: BBC
Substitutions: A->B

(R)eplace letter or (Q)uit: r
Letter from cryptogram: B
Replace with: C

Original cryptogram: ABC
With replacements: BCC
Substitutions: A->B B->C

(R)eplace letter of (Q)uit: q
• June 1st, 2012, 05:30 PM
Norm