REVscene Automotive Forum

REVscene Automotive Forum (https://www.revscene.net/forums/)
-   Computer Tech, Gaming & Electronics (https://www.revscene.net/forums/computer-tech-gaming-electronics_32/)
-   -   Need help with Java, arrays & strings & File I/O. (https://www.revscene.net/forums/690125-need-help-java-arrays-strings-file-i-o.html)

Recon604 11-12-2013 09:51 AM

Need help with Java, arrays & strings & File I/O.
 
Anyone knowledgeable with the language Java? I need help with writing a program that got to do with arrays & strings & File I/O.

You have been asked to read a text file word by word, and then sort the words in alphabetical order, and save them in sorted order in another file with following specifications:

1. Prompt user to input for file names.
2. Estimate the number of the words in the file, and then create an array of String such as String[] words = new String [ESTIMATED_SIZE] and store words in the array.
3. Change all world to lower case.
4. If words have a punctuation symbol in the beginning or at the end of the words, then remove the punctuation marks from the word, and keep the word.
5. You need to remove the following punctuation marks from each word; [ '.' (dot), ',' (comma), ';' (semi-colon), ':' (colon), '?' (question mark), '!' (exclamation), ' " ' (double quotation), ' \' ' (single quotation) , ')' (opening parentheses) , and '(' (closing parenthesis )].
6. If words still have any symbol except '-' (hyphen), then ignore the words.
7. Get rid of the words that contain digits.
8. Get rid of spaces from both side of the words.
9. Save the file in unique order. If there are many occurrences of the same word, then save only one of isntance of the word.


Check the sample input file and output file.

ForbiddenX 11-12-2013 11:27 AM

Do you have any progress done or specific questions? I can try and help. Probably won't be learning too much if you're just given the answers though :P

c_loke 11-12-2013 12:39 PM

Try breaking the problem down a bit. I'll take #2 for example.

You know that you have to get the works into a string array but to do this you first need to get the string of words. The string of words will need to come from somewhere, and in your case, it will come from a file. You then need to figure out how to read a text file to string.

How to create a Java String from the contents of a file? - Stack Overflow

First google search btw.

After you read in the file, you need to determine how you are going to split the words. Well you might want to split on the sentences, so you might have something that says

String [] words = stringofwords.split(" ");

Recon604 11-12-2013 01:08 PM

Quote:

Originally Posted by ForbiddenX (Post 8360302)
Do you have any progress done or specific questions? I can try and help. Probably won't be learning too much if you're just given the answers though :P

only got the part to read the input for file

Quote:

Originally Posted by c_loke (Post 8360348)
Try breaking the problem down a bit. I'll take #2 for example.

You know that you have to get the works into a string array but to do this you first need to get the string of words. The string of words will need to come from somewhere, and in your case, it will come from a file. You then need to figure out how to read a text file to string.

How to create a Java String from the contents of a file? - Stack Overflow

First google search btw.

After you read in the file, you need to determine how you are going to split the words. Well you might want to split on the sentences, so you might have something that says

String [] words = stringofwords.split(" ");

perfect! ill try to write it. Any of you are expects with java?


All times are GMT -8. The time now is 05:52 PM.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
SEO by vBSEO ©2011, Crawlability, Inc.
Revscene.net cannot be held accountable for the actions of its members nor does the opinions of the members represent that of Revscene.net