i was given an assignment to read from a file and find out the statistics of all the letters in that file. considering it is part of an arrays lesson, i am assuming we need to use those.
if someone could help me out, it would be greatly appreciated. thanks,

7 Years
Discussion Span
Last Post by ithelp

thats the thing... i dont know where to start

Start by deciding what you need to do to complete the assignment. From that list, decide what you already know how to do and what you do not. Decide the overall organization of the program. For example, what should the classes be? What should each class' data members be? Methods? What should be in main? What shouldn't? Should the methods be static? Etc. The answers may depend on how experienced with Java you are.

You need to be able to open and read from a file. Do you know how to do that? If not, tackle that. You also need to be able to set up counter array(s). Do you know how to do that? And you need to be able to parse the text and increment the counter array(s).

Regarding where to start, it's hard to say because we don't know your experience level. I would say, start with a single class, set up a basic default constructor, and call that constructor from main. Compile it and run it. Have it display "Hello World" in the constructor to make sure the constructor is being called (delete that later). Then set up the counter arrays, compile it and run it again, then post back here with the progress.


And definitely answer the question(s) Vernon posed. . what IS your experience level? What concepts do you know that he mentioned?


Ok, just for some things to think on:
- You need a "bin" to keep track of how many times you encountered each character. An array would work really well for that.
- Each letter, as a char, has an offset from 'a' that can be easily calculated.
- You need a zero-based index to access/increment the correct "bin" (element) for each letter's count.


Have an array of 26 integeres , count occurance of a-z there. Hope this will get you started for your project assignment.

This article has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.