View Full Version : Java searcher program CHALLANGE

01-08-2012, 09:09 PM
JAVA not JavaScript
create an application, searcher that takes two command line arguments: the starting directory and the target to find.

Searcher makes use of a recursive algorithm with the method signature: public static void scan (String path). This recursive algorithm needs to scan through directories and over file names in order to locate the specified file from the command line. You will, in all likelihood, need to make your FileIOHelper class described below. once you located your file you can stop executing and display the output of where the file was located.

Create a class called FileIOHelper. This has two private String arrays, directories and files. It also includes two public instance int variables dirLength and fileLength witch stores length of directories and files String arrays respectively.

it has one constructor that takes a file object, witch is used to determine the directory where you are going to be getting the information from. the constructor needs to iterate through each array element provided and assign the String to the right array(it's either a dir or file). Your arrays need to resize properly as you iterate through them.

The fileIOHelper has two public methods, getDirectories() and getFiles() both return their respective protected String arrays.

The FileIOHelper also has 2 private methods addToFile() and addToDirectory() witch both take a String and return a String array

1)keeping track of witch stack your working on currently - loggin information to a file through a static logger class.
2)using assertions where posible.:thumbsup:

01-08-2012, 09:11 PM
if s you say its JAVA not javascript, then you have posted in the wrong forum
There is another one for JAVA

Old Pedant
01-08-2012, 09:23 PM
But in any case, read rule 1.5 here: http://www.codingforums.com/rules.htm

You aren't supposed to post homework problems. We aren't supposed to answer them.

*IF* you do maybe 90% of the work and get stuck on *ONE OR TWO* aspects of it, then most people hill will give you a hand. But we aren't supposed to--and most of us won't--do your entire homework for you.

01-08-2012, 09:24 PM
then shud i remove it and how only option i see is to edit it but it wont be revoved just a blank thread which is not cool

01-08-2012, 09:27 PM
it's not a homework project im not at school anymore its a challenge to ppl who seem up to it i came across it and thought it was fun so y not share it.

Old Pedant
01-09-2012, 05:07 AM
I hope you won't take this wrong, but that's really only a "challenge" to a real Java novice. Somebody doing maybe a first class in Java.

Also, the directions make the task considerably more complicated than it needs to be.

The Java class java.io.File will automatically provide you with an array of all files and directories in a given directory and there is no reason to further separate them into one array of files and one of directories. There is also no reason for the four methods called for. Two methods (one static main method and one non-static recursive scan method) are all that are needed. Why would anybody complicate it beyond that?

Your whole "challenge" here can be written in a dozen or so lines of Java code, though admittedly it will be maybe 30 to 40 lines if you write it the silly way it is specified.