Lab 2: File System Tree
Due Date and Submission Requirements
- Due Date: Friday, January 31st at 11:59 p.m.
- Partner Information: This is an individual assignment. You are allowed to collaborate with other students, but each student must submit their individual, independent solution.
- Submission Instructions: Upload your solution (FileTree.java), to the BrightSpace(D2L) Lab 2 Dropbox.
The goal of this lab is:
- Gain experience using the Tree data structure
Directions
In this lab, you will build three more methods for the FileTree class we have been working on in
class (you should download a fresh set of files below) as a starting
point. You do not need to change any code beyond what is instructed. Complete the following
tasks:
1. Fill in the body for the public String getPath() method. This method will return a
String that shows the path from the root to current directory (e.g., ~/School/CSCI232/Labs)
2. Modify the existing method public boolean moveDown(String directory) so that
instead of reading in a single directory and moving into that directory, it can read in a path (e.g.,
Pictures/Pets/Tater) and navigate to the final directory in the path, if it exists. If the path is
not valid, it should return false. If part of the path is correct, but other parts are incorrect (e.g., /Pictures/Christmas/2023), the program should remain in the current directory (dont move to /Pictures). You may assume that the path provided is
relative to the current directory. Hint: you can use the Java .split(“/”) method on the
String path to create a list of all the directories you need to move down into.
3. Fill in the body for the public boolean remove(String directory). This method
will remove the selected directory, and all of its subdirectories, from the file system. If the
directory does not exist, the method should return false. If it does, remove it and return true.
You may assume that the directory provided is a child of the current directory (if it exists).
4. Now test your methods. The FileTreeManager class has the code to run the methods you are
writing. getPath() is executed by typing the pwd command, and remove() is execute by
typing the rm command. moveDown() is still executed by typing the
cd command. There is no code you need to add in this task, but make
sure you test your methods before you submit this lab.
That is three methods in total.
Required Output
When you run your program with the following commands, it should look exactly like output seen in in this screenshot .
Starting Code
Grading (10 points)
- 3 points - getPath() is correct.
- 4 points - moveDown() is correct.
- 3 points - remove() is correct.
NOTE: If your code does not compile, correctness cannot be verified and you won’t receive any
points for your code. Turn in code that compiles!