Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: Cryptogram, help please

  1. #1
    Junior Member
    Join Date
    Jun 2012
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Cryptogram, help please

    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 = Keyboard.readString("Enter cryptogram: ");
    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();
    replacement = Character.toLowerCase(Keyboard.readChar("Replace with: "));
    substitution2[i] = replacement;
    check = Keyboard.readChar("Make another substitution? (y/n) ");
    check = Character.toLowerCase(check); //prevent case conflicts
    subsMade++;
    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;
    }
    }
    }

  2. Default Related threads:


  3. #2
    Junior Member
    Join Date
    Jun 2012
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Cryptogram, help please

    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

  4. #3
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    20,973
    Thanks
    51
    Thanked 2,269 Times in 2,241 Posts

    Default Re: Cryptogram, help please

    Please Edit your post and wrap your code with[code=java]<YOUR CODE HERE>[/code] to get highlighting. The unformatted code is very hard to read.

    What does post#2 show? Does it show the correct execution of the program? If not, please edit it and add some comments to show where there is a problem and to show what the output should be.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Cryptogram Program help!
    By mmurphy281 in forum Java Theory & Questions
    Replies: 4
    Last Post: April 5th, 2012, 04:32 PM