38.8k views
3 votes
You will create a Folder class and a File class that will represent the File System on your computer. They should have all the proper member variables, setters and getters. The folder class will have a print function that prints out all subfolders and files. The file class will have a print function that prints out the name of the file. A Folder can contain zero or more Files. A Folder can also contain zero or more Sub-Folders. A File must be stored within a folder. If a folder is deleted all the files and sub-folders in the folder are also deleted. In the structure below we see php demo1 is a folder and has a sub-folder of Source Files. Recreate the structure below: 1. As part of the driver program print out the php_demo1 folder and all sub folders. All sub folders should also print out their content until the full structure above is printed. 2. Now delete the folder app and print out the full structure. 3. Now delete the folder public and print out the full structure.

User Bokov
by
8.4k points

1 Answer

1 vote

Final answer:

A Folder class represents a directory and manages multiple File and Sub-Folder objects, which are represented by the File class. Each class includes methods for setting, getting, and printing properties. The structure is printed, modified by deletion, and printed again using these methods.

Step-by-step explanation:

To model a simple file system using a Folder class and a File class, we need to ensure our Folder class can store and manage multiple Files and Sub-Folders. Each File should be contained within a Folder, and upon deletion of a Folder, all its contents should also be removed.

Folder Class

The Folder class should include:

  • A list of Files
  • A list of Sub-Folders
  • Methods to add or remove Files and Sub-Folders
  • A method to print all its contents

File Class

The File class should include:

  • A property for the name of the file
  • Methods to set and get the name
  • A method to print the name of the file

To recreate and print the structure, we would instantiate the Folder and File objects accordingly, and call the print function on the 'php_demo1' folder. To simulate deletion, we would remove 'app' and 'public' folders and then print the structure again to reflect the changes.

User Alan Bosco
by
7.5k points