Go Back   CodingForums.com > :: Server side development > Java and JSP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 02-27-2011, 04:34 PM   PM User | #1
schultetwin1
New to the CF scene

 
Join Date: Feb 2011
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
schultetwin1 is an unknown quantity at this point
Instance Variable Changes with New Object

I'm just learning java and I'm writing a program that compares the frequency of characters in a plaintext document and then in a cipher document. I use the frequencies of the letters in each document to find out which character goes with which, in order to decipher a text file.

I have a class FrequencyAnalysis, which creates an object, with a local variable of char[] key, in which the letters are stored in order of most common occurrence. I create a FrequencyAnalysis object for the plain text document, and the key is stored fine in its array, but when I create a FrequencyAnalysis object for the ciphered text, the key for the plain text document changes to the key for the ciphered document. Why does this happen?
Thanks.

I have attached the two classes, FrequencyAnalysis and then the class FrequencyAnalysisTester which creates the objects to this post.
Attached Files
File Type: txt ciphertext.txt (6.0 KB, 76 views)
File Type: txt FrequencyAnalysis.java.txt (7.9 KB, 71 views)
File Type: txt FrequencyAnalysisTester.java.txt (2.0 KB, 51 views)
File Type: txt plaintext.txt (8.7 KB, 38 views)
schultetwin1 is offline   Reply With Quote
Old 03-04-2011, 09:43 PM   PM User | #2
spchinta
New Coder

 
Join Date: Mar 2011
Location: USA
Posts: 23
Thanks: 0
Thanked 1 Time in 1 Post
spchinta is an unknown quantity at this point
because of this..

private static final char[] alphabet ..

Remove static, It will work for you(because it worked for me)
spchinta is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 05:10 PM.


Advertisement
Log in to turn off these ads.