Results 1 to 15 of 15
Like Tree1Likes
  • 1 Post By jim829

Thread: need help with assignment

  1. #1
    Join Date
    Nov 2013
    Posts
    29
    Rep Power
    0

    Default need help with assignment

    instructions

    Create a WordCounter class with a constructor that takes a file name as a parameter
    The class should have two fields: one for the file name and one for a HashMap to store word count information
    The constructor should call a private method, countWords, that reads in the file and counts the word frequencies
    The class should contain a get method for each field, as well as a print method that prints out the map in the following format: word: frequency
    When printing, the map should be sorted by either the word order or frequency (Hint: see Collections.sort)
    You should include the sample text file on Blackboard

    This is what i got so far
    Java Code:
    import java.io.File;
    import java.util.ArrayList;
    import java.util.Collections;
    import java.util.HashMap;
    import java.util.Scanner;
    
    
    
    public class WordCounter 
    {
    	// 2 fields for file name and hashmap
    	private ArrayList<String> fn,hm;
    	private Scanner x;
    
    	// constructor
    	public WordCounter(String frame)
    	{
    		countwords();
    
    	}
    	// methods
    	private void countwords ()
    	{
    		try{
    			x = new Scanner (new File("test.file.txt"));
    		System.out.println(Collections.frequency(fn, hm));
    		}
    		catch (Exception e){
    			System.out.println("File not found");
    		}
    	}
    	private void print() {
    		
    		
    	}
    	public static void main(String[] args) 
    	{
    		String fname = "test-file.txt";
    		if (args.length > 0)
    			fname = args[0];
    		
    		WordCounter wc = new WordCounter(fname);
    		wc.print();
    	}
    	
    
    }
    I still need help on steps 4 and 5

  2. #2
    KevinWorkman's Avatar
    KevinWorkman is online now Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,924
    Rep Power
    8

    Default Re: need help with assignment

    What does your code do? Where are you stuck? What are you confused about?
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    Join Date
    Nov 2013
    Posts
    29
    Rep Power
    0

    Default Re: need help with assignment

    lol i posted the instructions above the code, it needs to read a text file.

  4. #4
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    3,848
    Rep Power
    5

    Default Re: need help with assignment

    In stead of laughing out loud, take Kev's response as a sign that you are not making yourself clear no matter that you think you are. The particular problem here is: you are not asking any questions, you're only dumping your homework and then saying "I need help". Okay then. With what? Do you need book recommendations to further study the material?
    Last edited by gimbal2; 03-04-2014 at 05:40 PM. Reason: Jim's = Kev's. Whoopsie
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  5. #5
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,433
    Blog Entries
    7
    Rep Power
    20

    Default Re: need help with assignment

    Quote Originally Posted by gimbal2 View Post
    In stead of laughing out loud, take Jim's response [ ... ]
    Jim? What does Jim got to do with it? He's innocent.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  6. #6
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    3,848
    Rep Power
    5

    Default Re: need help with assignment

    *rubs eyes*

    What the heck! *sings* I'm going slightly mad. Let me edit that.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  7. #7
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    3,501
    Rep Power
    5

    Default Re: need help with assignment

    So you're mixing me up with Kevin? Hmmm, there are four possibilities:

    He's insulted, I'm insulted.
    He's honored, I'm honored.
    He's insulted, I'm honored.
    He's honored, I'm insulted.

    Regards,
    Jim
    KevinWorkman likes this.
    The Java™ Tutorial | SSCCE | Java Naming Conventions
    Poor planning our your part does not constitute an emergency on my part.

  8. #8
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,433
    Blog Entries
    7
    Rep Power
    20

    Default Re: need help with assignment

    Quote Originally Posted by jim829 View Post
    So you're mixing me up with Kevin? Hmmm, there are four possibilities:

    He's insulted, I'm insulted.
    He's honored, I'm honored.
    He's insulted, I'm honored.
    He's honored, I'm insulted.
    You are hereby allowed to poke Gimbal2, the silly old woman, with the soft cushions or even put him in the comfy chair!

    kindest regards,

    Cardinal Ximenez (<--- diabolical laughter ;-)
    cenosillicaphobia: the fear for an empty beer glass

  9. #9
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    3,848
    Rep Power
    5

    Default Re: need help with assignment

    Yeah poke away. I might like it too!
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  10. #10
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,433
    Blog Entries
    7
    Rep Power
    20

    Default Re: need help with assignment

    Quote Originally Posted by gimbal2 View Post
    Yeah poke away. I might like it too!
    Yes, and surprise! The festivities always end with a defenestration; shall I book you for a fine head-first defenestration and the pointy sticks?

    kindest regards,

    Jos (<-- putting the invitations on the mail)
    cenosillicaphobia: the fear for an empty beer glass

  11. #11
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    3,848
    Rep Power
    5

    Default Re: need help with assignment

    Get your wood away from me!

    Kindest regard,

    Erik (<--- purposely sending mixed signals)
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  12. #12
    KevinWorkman's Avatar
    KevinWorkman is online now Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,924
    Rep Power
    8

    Default Re: need help with assignment

    I'll take it as a compliment. Now I just have to keep working hard, and maybe one day I'll even be confused for camickr!
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  13. #13
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    3,848
    Rep Power
    5

    Default Re: need help with assignment

    The saddest part is that I already did the mix-up once before a couple of weeks ago, but I managed to correct it before anyone could notice that time. But do I learn from my mistakes? Nooooooooo.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  14. #14
    KevinWorkman's Avatar
    KevinWorkman is online now Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,924
    Rep Power
    8

    Default Re: need help with assignment

    Oh oh oh I realize I should use my name to my advantage and try to get people to confuse me for Kevin Glass!
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  15. #15
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    3,848
    Rep Power
    5

    Default Re: need help with assignment

    What are you talking about? You're effing KevinWorkman; people want to be you!
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

Similar Threads

  1. help with assignment
    By dnawiam in forum New To Java
    Replies: 1
    Last Post: 06-07-2013, 08:35 AM
  2. i need help with assignment
    By samwright92 in forum New To Java
    Replies: 5
    Last Post: 12-04-2012, 03:32 AM
  3. HW assignment help
    By mackavelirip in forum New To Java
    Replies: 5
    Last Post: 03-31-2011, 03:34 AM
  4. Need help with assignment! please
    By runawaykinms in forum Java Applets
    Replies: 2
    Last Post: 10-06-2010, 09:58 AM
  5. Need help with a assignment
    By helpMe.Java in forum New To Java
    Replies: 7
    Last Post: 06-06-2010, 04:49 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
  •