Recursive Structures Lab
Categories:
2 minute read
Introduction
The goal of this lab is to practice using recursion to interact with recursively structured data. One example of a recursively structured collection is the file system of a computer. A file system is made up of directories, each of which may contain additional directories, and so forth.
Please watch this 6-minute video by Gayle Laakmann McDowell :
Source Files
The following files are provided:
- DirectorySearcher.java – This (unfinished) class is responsible for recursively traversing a directory tree starting from a designated directory.
- DirectoryDriver.java – This is a driver class for executing the methods provided by
DirectorySearcher. As currently written, themainmethod uses aDirectorySearcherto list the contents of the current directory.
Instructions
- Download and test the two files above. Make sure you understand how the existing code works.
- if you run it as it is when you first download it, you should see something like:
bin (Directory) .classpath .settings (Directory) .project src (Directory)
- if you run it as it is when you first download it, you should see something like:
- Complete the
listDirectories(plural) method of theDirectorySearcherclass. Test your method by modifying the driver so that it calls this method instead oflistDirectory(singular).- Your solution should print a
"/"after each directory name and indent the files under each directory. For example,- if the starting path is
".", the output might look like this:./ bin/ DirectorySearcher.class DirectoryDriver.class .classpath .settings/ org.eclipse.jdt.core.prefs org.eclipse.core.resources.prefs .project src/ DirectorySearcher.java DirectoryDriver.java - if the starting path is
"../PA2", the output might look like this:PA2/ bin/ io/ FileProcessor.class CSVFileProcessor.class FileIdentifier.class CSVRepresentable.class testing/ VIPAccountTest.class FieldIdentifierTest.class AccountTest.class CSVFileProcessorTest.class .gitignore membership/ VIPAccount.class Account.class .classpath .project src/ io/ FileIdentifier.java CSVFileProcessor.java CSVRepresentable.java FileProcessor.java testing/ FieldIdentifierTest.java AccountTest.java CSVFileProcessorTest.java VIPAccountTest.java membership/ VIPAccount.java Account.java
- if the starting path is
- Your solution should print a
- Complete the
searchDirectoriesmethod of theDirectorySearcherclass. Test your method by modifying the driver; search for different patterns to make sure it works.- Your solution should print the path to each file that is found. (Just print the File object itself, rather than calling getName.) For example, if the search string is
"nt", the output might look like this:../PA2/bin/io/FileIdentifier.class ../PA2/bin/io/CSVRepresentable.class ../PA2/bin/testing/VIPAccountTest.class ../PA2/bin/testing/FieldIdentifierTest.class ../PA2/bin/testing/AccountTest.class ../PA2/bin/membership/VIPAccount.class ../PA2/bin/membership/Account.class ../PA2/src/io/FileIdentifier.java ../PA2/src/io/CSVRepresentable.java ../PA2/src/testing/FieldIdentifierTest.java ../PA2/src/testing/AccountTest.java ../PA2/src/testing/VIPAccountTest.java ../PA2/src/membership/VIPAccount.java ../PA2/src/membership/Account.java - while if you searched for empty string
"", the output might be:../PA2 ../PA2/bin ../PA2/bin/io ../PA2/bin/io/FileProcessor.class ../PA2/bin/io/CSVFileProcessor.class ../PA2/bin/io/FileIdentifier.class ../PA2/bin/io/CSVRepresentable.class ../PA2/bin/testing ../PA2/bin/testing/VIPAccountTest.class ../PA2/bin/testing/FieldIdentifierTest.class ../PA2/bin/testing/AccountTest.class ../PA2/bin/testing/CSVFileProcessorTest.class ../PA2/bin/.gitignore ../PA2/bin/membership ../PA2/bin/membership/VIPAccount.class ../PA2/bin/membership/Account.class ../PA2/.classpath ../PA2/.project ../PA2/src ../PA2/src/io ../PA2/src/io/FileIdentifier.java ../PA2/src/io/CSVFileProcessor.java ../PA2/src/io/CSVRepresentable.java ../PA2/src/io/FileProcessor.java ../PA2/src/testing ../PA2/src/testing/FieldIdentifierTest.java ../PA2/src/testing/AccountTest.java ../PA2/src/testing/CSVFileProcessorTest.java ../PA2/src/testing/VIPAccountTest.java ../PA2/src/membership ../PA2/src/membership/VIPAccount.java ../PA2/src/membership/Account.java
- Your solution should print the path to each file that is found. (Just print the File object itself, rather than calling getName.) For example, if the search string is
- Submit your completed
DirectorySearcher.javafile via GradeScope.
Last modified January 16, 2025: Rename deploy.yml to dont_deploy.yml (7438dab)