Hi guys, i need some help on my java homework.
i need a text box which will have a piece of text. then i must show how many times every word has written in the text. in my way of thinking i should add every word to an array and compare every word one by one but i am not sure how to separate words from text as element of the array and count them. i am newbie to java and really need some help or ideas. thx.

One way you could go about it:

. save the text entered in a String

. use the the String split method to create a String[]

. create a hashmap HashMap<String, Integer> and add entries to it using the values in String[] as the key with an initial value of zero

. iterate through the String[] again add one to the value for each corresponding key in String[]

At the end the hashmap will contain all the words as keys with the corresponding number of times they appear.

best start, though: grab your course books, and study them a bit.
no professor will ask you to write a gui if you don't understand enough of the java basics to actually use it.
your first step should be, try to write it yourself. if it doesn't work, show us the relevant code, error messages and ask specific questions.

do not expect us to make your homework for you.
1. we do not need an app like that, and for us it is not that important
2. you would get your degree by cheating (if you're lucky), which is bad for you as well as us. you might get a job you're not capable of doing, and some of us might lose that job to you

Comments
Good to see you back on the forums

dear stultuske,
1. title of the thread is help on java algorithm, it s not please help to do my homework
2. Nobody is in need of replying the posts, you dont have to have any benefit. People call it help.
3. if you didnt go to college let me tell you that no professor teach you everything, for a half of semester we saw only basics of java console apps then i got my mark without cheating and now my proff gave this project to do with using swing (thats the way it is in college)

btw i am sorry for arguing about something else on an it discussion community i just asked for an idea and previous post before your unnecessary post actually helped. thx.

1. might be, but you didn't provide us with any code whatsoever you wrote yourself, which does imply, you're expecting us to do it.
2. it's not 'helping', it's 'doing it for you' which, I can assure you, won't do you any good on the long run
3. I did, and I do have my degree. off course no teacher will tell you everything, since it would take a lot more years than they can spend on education. what you ask for specificly, the 'splitting up' of a String into parts, that has nothing to do with Swing, that has to do with basic Java applications (which you say you got pretty much figured out, so what's the problem?)

your professor is most likely trying to figure out whether or not you are capable of importing packages and using them the right way (like the awt and Swing packages, for instance), because, truly, your future employer will not limit your jobs to packages and techniques you saw in school.

if you want help on the Swing, check the Swing tutorials, you're bound to stumble on a few if you just google it.
if you're looking for a way to split the String objects in several Strings, I would suggest you either use the indexOf and substring methods of the class String, or you familiarize yourself with StringTokenizers

my first post was not to say we're not willing to help, it's just pointing out that we're here to point you in the right direction and help you solve any mistakes you've made. how can we do that, if you don't show us what you've done, and what your mistakes were?

Edited 6 Years Ago by stultuske: n/a

This article has been dead for over six months. Start a new discussion instead.