I need a some help!!

Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Oct 2006
Posts: 5
Reputation: silentcreeper is an unknown quantity at this point 
Solved Threads: 0
silentcreeper silentcreeper is offline Offline
Newbie Poster

I need a some help!!

 
0
  #1
Oct 10th, 2006
Hi, I have been working on a project for my java programming class but I just dont know where to even start.

here is what i was assigned


Your program must:
  • Not declare any class attributes. You will not need them in a carefully designed class.
  • Read a single speech text file into an array of words, and then print to the screen the total number of words found in the file. For example, the Fort Bragg speech contains 3654 words.
  • Display to the screen the number of unique words as well as the percentage of unique words to total words. For example, the Fort Bragg speech contains 995 unique words, representing 27% of the total.
  • Prompt the user for any word, and then display the number of occurrences of that word in the speech.
  • Output a text file that consists of a listing of the unique words in the speech with the number of occurrences of each word following the word. The file lists the words starting with those occurring most often and ending with those occurring once only. If you have words that occur the same number of times list them in alphabetical order.
I'm not asking anyone to do my whole project ... i just need some help getting started.

For example i dont know how to read or write text files and i am not sure how to manipulate arrays of strings.

Any help would be greatly appreciated
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 30
Reputation: Rayhan Muktader is an unknown quantity at this point 
Solved Threads: 3
Rayhan Muktader Rayhan Muktader is offline Offline
Light Poster

Re: I need a some help!!

 
0
  #2
Oct 11th, 2006
Umm.. what are you refering to when you say "class attributes"? Are you refering to instance variables?
The following page has an example of how to read from text files: http://www.javacoffeebreak.com/faq/faq0004.html
Try it, then ask a more specific question about arrays of strings.
Last edited by Rayhan Muktader; Oct 11th, 2006 at 1:26 am.
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 5
Reputation: silentcreeper is an unknown quantity at this point 
Solved Threads: 0
silentcreeper silentcreeper is offline Offline
Newbie Poster

Re: I need a some help!!

 
0
  #3
Oct 11th, 2006
Class attributes are attributes declared within the class but outside of all your methods ... for some reason my teacher doesnt want us to use these. I'm not sure yet if this is going to significantly complicate things ... I dont think it will make that much of a difference.

Thanks for the link ... i will look over that and see what i can do then i will ask again if i get stuck
Reply With Quote Quick reply to this message  
Join Date: Mar 2004
Posts: 765
Reputation: Phaelax is on a distinguished road 
Solved Threads: 38
Phaelax Phaelax is offline Offline
Master Poster

Re: I need a some help!!

 
0
  #4
Oct 11th, 2006
For reading the file:
  1. File file = new File("C:/myFileHere.txt");
  2. BufferedReader in = null;
  3. try
  4. {
  5. in = new BufferedReader(new FileReader(file));
  6.  
  7. String line;
  8. //loop through each line in the file
  9. while ((line = in.readLine()) != null)
  10. {
  11. //split line up by any words separated by a space
  12. String[] words = line.split(" ");
  13. //get array count for total words on this line
  14. //loop through words and keep track of unique words with a hashmap
  15. }
  16. }
  17. catch (Exception e)
  18. {}


You can use HashMap to put each word in as a key. For each word you add, check to see if it's already a key. If so, increase the value of that key. This'll keep track of how many times a word shows up. The size of the hashmap will tell you how many unique words there are and the value of each key will tell you how many times that word shows up.

After that, the rest is just simple math.
Last edited by Phaelax; Oct 11th, 2006 at 2:54 pm.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the Java Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC