Results 21 to 40 of 41
- 01-21-2009, 04:18 AM #21
Member
- Join Date
- Dec 2008
- Posts
- 24
- Rep Power
- 0
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
-
Why not give it a try? You've got nothing to lose.do I need to put in the array and then try analyzing it
- 01-21-2009, 04:29 AM #23
Member
- Join Date
- Dec 2008
- Posts
- 24
- Rep Power
- 0
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 ... ?
- 01-21-2009, 04:32 AM #24
Member
- Join Date
- Dec 2008
- Posts
- 24
- Rep Power
- 0
.readLine() <- will always read just one line at the time, until put it the loop ? but how is this going to work ?
-
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!
- 01-21-2009, 05:49 AM #26
hey u might want to change this line.
also, there is something wrong w/ the calculation for tempIndex. you'll wana look into that.Java Code:if (sentence.equals("***")) { System.out.println("Enter any key to continue: "); inputs.nextLine(); // CHANGED!!!!!! }
here's the original values for tempIndex:
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 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:
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)
- 01-21-2009, 06:37 AM #27
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)
- 01-21-2009, 07:26 AM #28
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)
- 01-21-2009, 05:42 PM #29
Member
- Join Date
- Dec 2008
- Posts
- 24
- Rep Power
- 0
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
- 01-21-2009, 06:29 PM #30
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)
- 01-21-2009, 06:34 PM #31
Member
- Join Date
- Dec 2008
- Posts
- 24
- Rep Power
- 0
- 01-21-2009, 06:59 PM #32
Member
- Join Date
- Dec 2008
- Posts
- 24
- Rep Power
- 0
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.
- 01-21-2009, 07:10 PM #33
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)
- 01-21-2009, 07:22 PM #34
Member
- Join Date
- Dec 2008
- Posts
- 24
- Rep Power
- 0
doesn't really workJava 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)); } } } }
output:
this program is getting annoying...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
Last edited by Gigi; 01-21-2009 at 07:24 PM.
-
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.
- 01-21-2009, 07:30 PM #36
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)
- 01-21-2009, 07:41 PM #37
Member
- Join Date
- Dec 2008
- Posts
- 24
- Rep Power
- 0
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 ?
- 01-21-2009, 07:49 PM #38
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)
- 01-21-2009, 07:54 PM #39
Member
- Join Date
- Dec 2008
- Posts
- 24
- Rep Power
- 0
I just can't figure out what is wrong ?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)); } } } }
- 01-21-2009, 08:15 PM #40
Member
- Join Date
- Dec 2008
- Posts
- 24
- Rep Power
- 0
Similar Threads
-
Reading Integers from a text file
By tress in forum New To JavaReplies: 6Last Post: 02-26-2011, 05:45 PM -
[SOLVED] Reading a text file into an Array
By DonCash in forum New To JavaReplies: 13Last Post: 01-25-2011, 12:51 AM -
help...! about reading a text file and finding their average
By nemesis in forum New To JavaReplies: 20Last Post: 10-20-2008, 11:02 AM -
Reading two text file and sum them up
By matt_well in forum New To JavaReplies: 36Last Post: 07-22-2008, 02:55 AM -
Reading text file
By Lennon-Guru in forum New To JavaReplies: 1Last Post: 12-15-2007, 11:38 PM


LinkBack URL
About LinkBacks


Bookmarks