Data Structures and Algorithms

Algorithms and Data Structures
Assignment – Generalized Trees
Introduction
The file system on most modern operating systems is organized as a generalized tree structure. The nodes of the tree are regular files and subdirectories. The subdirectories provide hierarchical structure, as they can contain other subdirectories as well as regular files.
For this assignment, write a Java program that recursively traverses the file system starting at a fully qualified subdirectory. The subdirectory must be provided as a command line parameter. When processing begins, the first line of output is the fully qualified subdirectory.
For each subdirectory encountered, get a list of the files in that subdirectory. For each entry in the list, if it is a regular file, output the file name and extension. Do not include the path name; just the file name and extension. If the file is a subdirectory, output just the subdirectory name; do not include the pathname that precedes the subdirectory name. In either case, after outputting the name, recursively descend into subdirectory and continue. You may recognize this as a pre-order traversal.
For each line of output, prefix the file or subdirectory name with indentation that provides a visual indication of the depth of the recursive descent.
Students are responsible for
· public FileTreeWalk(String pathname)
· public String listAllFiles()
· public String toString()
class FileTreeWalk
FileTreeWalk is a Java class used for traversing a file system. In addition to a constructor, the class provides two public methods for traversing the file system, and a public toString method for displaying the traversal results.
The public interface to the class follows:
public FileTreeWalk (String pathname)
The constructor takes a String parameter that specifies a pathname. The pathname is a starting point for the file system traversal. The parameter is either a fully qualified path name, or a relative pathname. Fully qualified pathnames start with an optional drive letter, or a slash. On other operating systems (e.g., Linux, Unix), a fully qualified pathname starts with a slash. Relative pathnames start at the current working directory. In either case, the pathname parameter specifies where the file system traversal is supposed to begin.
As FileTreeWalk traverses the file system, it adds file names and subdirectory names to a generalized tree structure that when finished will represent the current state of the file system from the starting point specified by the String parameter, pathname.
public String listAllFiles ()
This method returns a string representation of the generalized tree of the file system starting at the pathname specified in and built by the constructor. Provided the argument to the constructor is the string, “C:\UsersBigJoeDocuments”, the output might look like this:
C:\UsersBigJoeDocuments
FileTreeWalk
Build
Classes
FileTreeWalk
FileTreeWalk.class
.netbeans_automatic_build
.netbeans_update_resources
nbproject
private
private.properties
build-impl.xml
henfiles.properties
project.properties
project.xml
src
filetreewalk
FileTreeWalk.java
test
build.xml
manifest.mf
assignment03.docx
Notice that the indentation reflects the position of the files within the files system hierarchy. Do not store the indentation in the tree structure. Add it during the pre-order traversal of the tree.
From the example, notice that subdirectory FileTreeWalk contains four subdirectories (Build, nbproject, src, and test), and two regular files (build.xml, and manifest.mf). Also notice that when a subdirectory is first encountered, it’s name is output before the files within it, making it a pre-order traversal.
public String toString ()
This method returns a String representation of the file system traversal created by the constructor. It just returns the String value that listAllFiles()returns.
Additional Note
Java 8 provides a class, java.nio.file.Files, that encapsulates all of the recursion needed to solve this assignment with no recursion in the calling code (code that you will write). Which is great. But this assignment is to help you better understand recursion. Do not use java.nio.file.Files for this assignment. If you do use it, you can pretty much count on receiving no credit for the assignment.
Prior to Java 8, the way you would approach this problem is to use java.io. File. Use this class and its methods to traverse the file system. An example of this method is provided on the canvas module.
Do not include a public static void main method to your java class. I will be using my own class for testing.

Place your order
(550 words)

Approximate price: $22

Calculate the price of your order

550 words
We'll send you the first draft for approval by September 11, 2018 at 10:52 AM
Total price:
$26
The price is based on these factors:
Academic level
Number of pages
Urgency
Basic features
  • Free title page and bibliography
  • Unlimited revisions
  • Plagiarism-free guarantee
  • Money-back guarantee
  • 24/7 support
On-demand options
  • Writer’s samples
  • Part-by-part delivery
  • Overnight delivery
  • Copies of used sources
  • Expert Proofreading
Paper format
  • 275 words per page
  • 12 pt Arial/Times New Roman
  • Double line spacing
  • Any citation style (APA, MLA, Chicago/Turabian, Harvard)

Our guarantees

Delivering a high-quality product at a reasonable price is not enough anymore.
That’s why we have developed 5 beneficial guarantees that will make your experience with our service enjoyable, easy, and safe.

Money-back guarantee

You have to be 100% sure of the quality of your product to give a money-back guarantee. This describes us perfectly. Make sure that this guarantee is totally transparent.

Read more

Zero-plagiarism guarantee

Each paper is composed from scratch, according to your instructions. It is then checked by our plagiarism-detection software. There is no gap where plagiarism could squeeze in.

Read more

Free-revision policy

Thanks to our free revisions, there is no way for you to be unsatisfied. We will work on your paper until you are completely happy with the result.

Read more

Privacy policy

Your email is safe, as we store it according to international data protection rules. Your bank details are secure, as we use only reliable payment systems.

Read more

Fair-cooperation guarantee

By sending us your money, you buy the service we provide. Check out our terms and conditions if you prefer business talks to be laid out in official language.

Read more
Open chat
1
You can contact our live agent via WhatsApp! Via + 1 929 473-0077

Feel free to ask questions, clarifications, or discounts available when placing an order.

Order your essay today and save 20% with the discount code GURUH