Page 2 of 3 FirstFirst 123 LastLast
Results 21 to 40 of 41
  1. #21
    Gigi is offline Member
    Join Date
    Dec 2008
    Posts
    24
    Rep Power
    0

    Default

    do I need to put in the array and then try analyzing it ? I don't really have much time, because it's already end of the course and we haven't even looked at Files and Exception Handling, so I'm kind doing everything off that little problem that I did. I would reallyy appreciate if you could give me a hand with this one

  2. #22
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

    Default

    do I need to put in the array and then try analyzing it
    Why not give it a try? You've got nothing to lose.

  3. #23
    Gigi is offline Member
    Join Date
    Dec 2008
    Posts
    24
    Rep Power
    0

    Default

    I don't really get, since it reads each line and then does the decryption, I don't know how to tell not to analyze it after its read each line, but wait until it reaches the *** part and ... ?

  4. #24
    Gigi is offline Member
    Join Date
    Dec 2008
    Posts
    24
    Rep Power
    0

    Default

    .readLine() <- will always read just one line at the time, until put it the loop ? but how is this going to work ?

  5. #25
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

    Default

    it only analyzes each line because you tell it to analyze after reading each line. If you don't want it to do that, then don't tell it to do that. If you only want it to analyze after it either reaches *** or it runs out of lines, then you must tell it to only analyze after reaching these points. Again, the program code follows the logic. Anyway, it's late, I'm on call at the hospital tomorrow, and I'm going to bed. Best of luck to you and to your endeavors!

  6. #26
    angryboy's Avatar
    angryboy is offline Senior Member
    Join Date
    Jan 2009
    Posts
    742
    Rep Power
    6

    Default

    hey u might want to change this line.
    Java Code:
    if (sentence.equals("***"))
    {
        System.out.println("Enter any key to continue: ");
        inputs.nextLine(); // CHANGED!!!!!!
    }
    also, there is something wrong w/ the calculation for tempIndex. you'll wana look into that.

    here's the original values for tempIndex:
    Java Code:
    S:\SVN\gigi>java Problem2CeasarCipher
    22
    THERE WAS NOTHING SO VERY REMARKABLE IN THAT
    11
    YZC OTO LWTNP ESTYV TE DZ GPCJ XFNS ZFE ZQ ESP HLJ
    11
    EZ SPLC ESP CLMMTE DLJ EZ TEDPWQ
    22
    OH DEAR OH DEAR I SHALL BE LATE
    Enter any key to continue:
    here's what happend after I changed tempIndex = 22.
    Java Code:
    S:\SVN\gigi>java Problem2CeasarCipher
    22
    THERE WAS NOTHING SO VERY REMARKABLE IN THAT
    22
    NOR DID ALICE THINK IT SO VERY MUCH OUT OF THE WAY
    22
    TO HEAR THE RABBIT SAY TO ITSELF
    22
    OH DEAR OH DEAR I SHALL BE LATE
    Enter any key to continue:
    USE CODE TAGS--> [CODE]...[/CODE]
    Get NotePad++ (free)

  7. #27
    angryboy's Avatar
    angryboy is offline Senior Member
    Join Date
    Jan 2009
    Posts
    742
    Rep Power
    6

    Default

    i see your problem. your encoding seed is per paragraph. but your decoding seed is per line. so you need to change the loop to not change tempIndex until it hits ***.
    USE CODE TAGS--> [CODE]...[/CODE]
    Get NotePad++ (free)

  8. #28
    angryboy's Avatar
    angryboy is offline Senior Member
    Join Date
    Jan 2009
    Posts
    742
    Rep Power
    6

    Default Got it working nicely.

    yup, just set tempIndex every paragraph instead of every sentence.
    also reset values for all of your variables such as: wordLetters,arrayIndex,offset, tempIndex, tempHighest, etc... to zero.

    Sorry, i'm not allow to post complete solutions or else CJSLMAN will b-slap me for it.

    Java Code:
    S:\SVN\gigi>java Problem2CeasarCipher
    THERE WAS NOTHING SO VERY REMARKABLE IN THAT
    NOR DID ALICE THINK IT SO VERY MUCH OUT OF THE WAY
    TO HEAR THE RABBIT SAY TO ITSELF
    OH DEAR OH DEAR I SHALL BE LATE
    Enter any key to continue:
    
    EITHER THE WELL WAS VERY DEEP OR SHE FELL VERY SLOWLY
    FOR SHE HAD PLENTY OF TIME AS SHE WENT DOWN TO LOOK ABOUT HER
    AND TO WONDER WHAT WAS GOING TO HAPPEN NEXT
    FIRST SHE TRIED TO LOOK DOWN AND MAKE OUT
    WHAT SHE WAS COMING TO BUT IT WAS TOO DARK TO SEE ANYTHING
    Enter any key to continue:
    
    THEN SHE LOOKED AT THE SIDES OF THE WELL
    AND NOTICED THAT THEY WERE FILLED WITH CUPBOARDS AND BOOKSHELVES
    HERE AND THERE SHE SAW MAPS AND PICTURES HUNG UPON PEGS
    SHE TOOK DOWN A JAR FROM ONE OF THE SHELVES AS SHE PASSED
    IT WAS LABELLED ORANGE MARMALADE
    BUT TO HER GREAT DISAPPOINTMENT IT WAS EMPTY
    SHE DID NOT LIKE TO DROP THE JAR FOR FEAR OF KILLING SOMEBODY
    SO MANAGED TO PUT IT INTO ONE OF THE CUPBOARDS AS SHE FELL PAST IT
    USE CODE TAGS--> [CODE]...[/CODE]
    Get NotePad++ (free)

  9. #29
    Gigi is offline Member
    Join Date
    Dec 2008
    Posts
    24
    Rep Power
    0

    Default

    I really need this done and I have no idea how to set tempIndex every paragraph instead of every sentence. Do I need to create an array that will store it ? or what ? I don't want to spend 5 hours doing this question, or you can just tell me how it's done

  10. #30
    angryboy's Avatar
    angryboy is offline Senior Member
    Join Date
    Jan 2009
    Posts
    742
    Rep Power
    6

    Default

    no no, not every paragraph. only set tempIndex to the max value of the first line of each paragraph. don't calculate tempIndex for the 2nd lines and so on.

    here's the logic:

    if input == ***, wait for user input, and reset variables.
    else if sentence == firstSentence, then calculate for tempIndex and decode.
    else just decode.
    output decoded data.
    USE CODE TAGS--> [CODE]...[/CODE]
    Get NotePad++ (free)

  11. #31
    Gigi is offline Member
    Join Date
    Dec 2008
    Posts
    24
    Rep Power
    0

    Default

    Quote Originally Posted by angryboy View Post
    no no, not every paragraph. only set tempIndex to the max value of the first line of each paragraph. don't calculate tempIndex for the 2nd lines and so on.

    here's the logic:

    if input == ***, wait for user input, and reset variables.
    else if sentence == firstSentence, then calculate for tempIndex and decode.
    else just decode.
    output decoded data.
    I don't undestand this line:
    else if sentence == firstSentence,
    what is firstSentence ? and how it goes
    can you just type the code here ?

  12. #32
    Gigi is offline Member
    Join Date
    Dec 2008
    Posts
    24
    Rep Power
    0

    Default

    else if sentence == firstSentence, then calculate for tempIndex and decode. What is firstSentence that you comparing to ? is this case, how would you distinguish sentences in the file(which one is the first ?) because the programs read it one after another, it doesn't know which one is the first
    Last edited by Gigi; 01-21-2009 at 07:05 PM.

  13. #33
    angryboy's Avatar
    angryboy is offline Senior Member
    Join Date
    Jan 2009
    Posts
    742
    Rep Power
    6

    Default

    i just made it up. but you can use some cheap code like this:

    Java Code:
    boolean firstSentence = false
    if ( sentence == ***) then firstSentence = true.
    if (firstSentence) then calc tempIndex and decode.
    else just decode.
    USE CODE TAGS--> [CODE]...[/CODE]
    Get NotePad++ (free)

  14. #34
    Gigi is offline Member
    Join Date
    Dec 2008
    Posts
    24
    Rep Power
    0

    Default

    Java Code:
    import java.util.Scanner;
    //import java.util.ArrayList;
    import java.io.*;
    
    public class Problem2CeasarCipher
    {
        public static void main(String[] args) throws IOException
        {
         BufferedReader input = new BufferedReader(new FileReader("DATA21.txt")); 
         Scanner inputs = new Scanner(System.in); 
        
         char[] wordLetters;
         int[] letterCounts = new int[26];
         int arrayIndex;
         int offset;
         int tempIndex = 0;
         int tempHighest = 0;
         String sentence = "";   
         //ArrayList decodedText = new ArrayList();
        boolean firstSentence = false;
    
        
    while ((sentence = input.readLine()) != null)
    {    
      
       
      if (sentence.equals("***"))
            {
            firstSentence = true;
            System.out.println("Enter any key to continue: ");
            inputs.nextLine();
           
                      arrayIndex=0;
                      offset =0;   
                      tempIndex =0;
                       tempHighest = 0;
                       wordLetters = null;
    
           }
    
     
    else if (firstSentence)
      {  
       
           String copySentence = sentence;
           sentence = sentence.replaceAll(" ", "");
           wordLetters = sentence.toCharArray();
         
          for(int letter = 0; letter < wordLetters.length; letter++)
         {
            offset = wordLetters[letter] - 65;
            letterCounts[offset] +=1;
         }
         
         for(int i = 0; i <= 25; i++)
          {
           if (letterCounts[i] > tempHighest)
           { 
             tempHighest = letterCounts[i];
             tempIndex = i;
            }
          } 
     
             testProblem2CeasarCipher encoding = new testProblem2CeasarCipher(tempIndex);    
             System.out.println(encoding.decode(copySentence));
        }     
         else
            {
              testProblem2CeasarCipher encoding = new testProblem2CeasarCipher(tempIndex);    
              //System.out.println(encoding.decode(copySentence));
            }
        
         }  
       }    
    }
    doesn't really work

    output:

    Java Code:
    Enter any key to continue: 
     [DrJava Input Box]
    EITHER THE WELL WAS VERY DEEP OR SHE FELL VERY SLOWLY
    FOR SHE HAD PLENTY OF TIME AS SHE WENT DOWN TO LOOK ABOUT HER
    AND TO WONDER WHAT WAS GOING TO HAPPEN NEXT
    FIRST SHE TRIED TO LOOK DOWN AND MAKE OUT
    WHAT SHE WAS COMING TO BUT IT WAS TOO DARK TO SEE ANYTHING
    Enter any key to continue: 
     [DrJava Input Box]
    FTQZ ETQ XAAWQP MF FTQ EUPQE AR FTQ IQXX
    MZP ZAFUOQP FTMF FTQK IQDQ RUXXQP IUFT OGBNAMDPE MZP NAAWETQXHQE
    TQDQ MZP FTQDQ ETQ EMI YMBE MZP BUOFGDQE TGZS GBAZ BQSE
    ETQ FAAW PAIZ M VMD RDAY AZQ AR FTQ ETQXHQE ME ETQ BMEEQP
    UF IME XMNQXXQP ADMZSQ YMDYMXMPQ
    NGF FA TQD SDQMF PUEMBBAUZFYQZF UF IME QYBFK
    ETQ PUP ZAF XUWQ FA PDAB FTQ VMD RAD RQMD AR WUXXUZS EAYQNAPK
    EA YMZMSQP FA BGF UF UZFA AZQ AR FTQ OGBNAMDPE ME ETQ RQXX BMEF UF
    this program is getting annoying...
    Last edited by Gigi; 01-21-2009 at 07:24 PM.

  15. #35
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

    Default

    You need to not do your analysis when reading a sentence unless either *** is reached or the end of the text is reached. Right now, it appears that you're doing the exact opposite.

    Myself, I try to walk through the logic of my program by stepping through the program on paper thinking "now what will it do when it reads the first line" then looping and stepping through it again until *** is reached. If you do this for one of your "paragraphs" of data, you'll see what your mistakes are.
    Last edited by Fubarable; 01-21-2009 at 07:31 PM.

  16. #36
    angryboy's Avatar
    angryboy is offline Senior Member
    Join Date
    Jan 2009
    Posts
    742
    Rep Power
    6

    Default

    keep trying, you'll get it. well the code was badly written to begin with... also, boolean firstSentence neeeds to be inside the while loop.
    USE CODE TAGS--> [CODE]...[/CODE]
    Get NotePad++ (free)

  17. #37
    Gigi is offline Member
    Join Date
    Dec 2008
    Posts
    24
    Rep Power
    0

    Default

    Java Code:
    import java.util.Scanner;
    //import java.util.ArrayList;
    import java.io.*;
    
    public class Problem2CeasarCipher
    {
        public static void main(String[] args) throws IOException
        {
         BufferedReader input = new BufferedReader(new FileReader("DATA21.txt")); 
         Scanner inputs = new Scanner(System.in); 
        
         char[] wordLetters;
         int[] letterCounts = new int[26];
         int arrayIndex;
         int offset;
         int tempIndex = 0;
         int tempHighest = 0;
         String sentence = "";   
         //ArrayList decodedText = new ArrayList();
        
        
    while ((sentence = input.readLine()) != null)
    {    
        boolean firstSentence = false;
       
      if (sentence.equals("***"))
            {
            firstSentence = true;
            System.out.println("Enter any key to continue: ");
            inputs.nextLine();
           
                      arrayIndex=0;
                      offset =0;   
                      tempIndex =0;
                       tempHighest = 0;
                       wordLetters = null;
    
           }
    
     
    else if (firstSentence)
      {  
       testProblem2CeasarCipher encoding = new testProblem2CeasarCipher(tempIndex);    
              //System.out.println(encoding.decode(copySentence));
           
    
        }     
         else
            {
             
             String copySentence = sentence;
           sentence = sentence.replaceAll(" ", "");
           wordLetters = sentence.toCharArray();
         
          for(int letter = 0; letter < wordLetters.length; letter++)
         {
            offset = wordLetters[letter] - 65;
            letterCounts[offset] +=1;
         }
         
         for(int i = 0; i <= 25; i++)
          {
           if (letterCounts[i] > tempHighest)
           { 
             tempHighest = letterCounts[i];
             tempIndex = i;
            }
          } 
     
             testProblem2CeasarCipher encoding = new testProblem2CeasarCipher(tempIndex);    
    
            }
        
         }  
       }    
    }
    Java Code:
    Enter any key to continue: 
     [DrJava Input Box]
    Enter any key to continue:

    I can't get it seriosly, I'm just too weak for this and I'm running out of time, I still have to study for the exam, can you just tell me what EXACTLY needs to be changed? because I can do this all day long without any progress ?

  18. #38
    angryboy's Avatar
    angryboy is offline Senior Member
    Join Date
    Jan 2009
    Posts
    742
    Rep Power
    6

    Default

    i can't because i rewrote the whole thing completly different from yours. but it looks like u need to move some stuff out of the else block. try moving this line out.

    testProblem2CeasarCipher...

    then try moving other stuff out too. gtg.
    USE CODE TAGS--> [CODE]...[/CODE]
    Get NotePad++ (free)

  19. #39
    Gigi is offline Member
    Join Date
    Dec 2008
    Posts
    24
    Rep Power
    0

    Default

    Java Code:
    import java.util.Scanner;
    //import java.util.ArrayList;
    import java.io.*;
    
    public class Problem2CeasarCipher
    {
        public static void main(String[] args) throws IOException
        {
         BufferedReader input = new BufferedReader(new FileReader("DATA21.txt")); 
         Scanner inputs = new Scanner(System.in); 
        
         char[] wordLetters;
         int[] letterCounts = new int[26];
         int arrayIndex;
         int offset;
         int tempIndex = 0;
         int tempHighest = 0;
         String sentence = "";   
         //ArrayList decodedText = new ArrayList();
        
        
    while ((sentence = input.readLine()) != null)
    {    
        boolean firstSentence = false;
       
      if (sentence.equals("***"))
            {
            firstSentence = true;
            System.out.println("Enter any key to continue: ");
            inputs.nextLine();
           
                      arrayIndex=0;
                      offset =0;   
                      tempIndex =0;
                       tempHighest = 0;
                       wordLetters = null;
    
           }
    
     
    else if (firstSentence)
      {  
             String copySentence = sentence;
           sentence = sentence.replaceAll(" ", "");
           wordLetters = sentence.toCharArray();
         
          for(int letter = 0; letter < wordLetters.length; letter++)
         {
            offset = wordLetters[letter] - 65;
            letterCounts[offset] +=1;
         }
         
         for(int i = 0; i <= 25; i++)
          {
           if (letterCounts[i] > tempHighest)
           { 
             tempHighest = letterCounts[i];
             tempIndex = i;
            }
          } 
     
             testProblem2CeasarCipher encoding = new testProblem2CeasarCipher(tempIndex);    
         System.out.println(encoding.decode(copySentence));
      
    
    
        }     
         else
            {
               testProblem2CeasarCipher encoding = new testProblem2CeasarCipher(tempIndex);    
              //System.out.println(encoding.decode(copySentence));
     
            }
        
         }  
       }    
    }
    I just can't figure out what is wrong ?

  20. #40
    Gigi is offline Member
    Join Date
    Dec 2008
    Posts
    24
    Rep Power
    0

Page 2 of 3 FirstFirst 123 LastLast

Similar Threads

  1. Reading Integers from a text file
    By tress in forum New To Java
    Replies: 6
    Last Post: 02-26-2011, 05:45 PM
  2. [SOLVED] Reading a text file into an Array
    By DonCash in forum New To Java
    Replies: 13
    Last Post: 01-25-2011, 12:51 AM
  3. Replies: 20
    Last Post: 10-20-2008, 11:02 AM
  4. Reading two text file and sum them up
    By matt_well in forum New To Java
    Replies: 36
    Last Post: 07-22-2008, 02:55 AM
  5. Reading text file
    By Lennon-Guru in forum New To Java
    Replies: 1
    Last Post: 12-15-2007, 11:38 PM

Posting Permissions

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