Description
You have been provided with a Main.java file that implements a data structure for representing the
directory hierarchy of a file system in a computer. The file includes an interface FSObject and three
classes that implement the interface and contain a constructor and getters. These three classes are:
A class File which has two fields: a name and the size of the file
A class Directory which has two fields: a name and a list of the file system objects the directory
contains
A class Link which has two fields: a name and the path to the file or directory that it links to
The code also contains test code in the main function that is expected to work for a correct solution. Do
not modify this test code.
1. In main, create a value myFS of type FSObject that stores a file system object with the
following hierarchy:
dirA
+—- dirB
| +—- dirC
| | +—- file1 (4096 B)
| | +—- file2 (2097152 B)
| | +—- linkX -> dirA/dirD/file4
| +—- linkY -> dirA/dirD/file4
+—- dirD
+—- file3 (4194304 B)
+—- file4 (128 B)
+—- linkZ -> dirA/dirB/dirC/file1
2. Add an instance method totalSize that returns the total size of all the files in the hierarchy.
3. Create a visitor FSObjectVisitor that visits FSObject and its subtypes. You may modify
FSObject and its subtypes to accept FSObjectVisitor.
4. Use FSObjectVisitor to define a custom visitor called PrintLargeFilesVisitor that
prints the names of all the files larger than 1 MiB (1048576 B).
Assessment
Solutions should be:
Correct
In good style, including indentation and line breaks
Written using features discussed in class
Submission Instructions
Submit your Main.java file via Moodle. Do not submit any other files or compressed folders.