Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

HCC Sweets has identified a serious problem and you are being asked to use your programming skills to help solve it. It seems the employees

HCC Sweets has identified a serious problem and you are being asked to use your programming skills to help solve it. It seems the employees are filling their hard disks up and dont know how to fix it! Since they just dont want to delete random files for fear of deleting something important, a method needs to be devised to determine whats consuming all the space. Your task is to write a Java program to scan a given directory (which could be the root directly of the hard disk) that adds up the size of all files and subdirectories beneath it recursively, and then print out the top twenty files or directories by size. The size of a file can be found using the Files.size method, but for a directory this method does not return the total size of everything contained within it. You must compute that yourself recursively.

At a minimum youll need to write two classes (there could be more, see the different levels below), one that defines a DirectoryEntry that encapsulates the name and size of the file or directory, and a class for your main program. Note youll need to use the Path, Files, and DirectoryStream classes we discussed in module 4 to process and interrogate the file system. Youll need to write a method that iterates over a passed directory path recursively, returning the total size of that directory as an integer. The total size is the sum of all files and directories contained in that directory. Youll also need to pass in a collection object that stores the DirectoryEntry objects found during the scan. As each directory or file is found, it is added to this collection. After the directory scan is complete, you must sort the collection in descending order by size and then print out the top twenty paths and their total size in bytes.

More specific requirements:

When the program starts, it must ask for what directory to scan. If the user enters a blank directory (by hitting just the enter key with nothing else), default to the current directory.

If the root directory is given as the directory to scan, the program should process everything on the hard disk which is likely tens of thousands of entries. Therefore, after every 5000 entries are processed, print a status message of the form: Processed x files/directories, where x is the count, e.g., 5000, 10000, 15000, etc. This is to provide feedback to the user.

If an error occurs processing a file or directory, display a message, Cannot process file, where file is the absolute path of the file, and just skip it (meaning dont include it in the results).

After finishing the scan, and before printing the top twenty files/directories by size, the program must print the total number of files and directories found.

When printing the top twenty results, display each path using a left justified, 50 character width, and a 15 digit width for the size. Ensure the size is printed with thousands place comma separators. However, if the length of the path is more than 50 characters long, prefix the string to it and print the last 47 characters.

Credit for this assignment comes in three levels. Youll need to sort the results by descending size. The maximum grade will vary depending on how you implement this sort:

Level 1: If you use the built-in Collections.sort method to do it, the maximum grade is 60 out of 70 points.

Level 2: If you implement a Selection Sort class and use it to sort the results, the maximum grade is 70 out of 70 points.

Level 3: EXTRA CREDIT. If you implement a Merge Sort class that uses recursion to sort the results, the maximum grade is 80 out of 70 points. You must use recursion to receive the additional points.

Note there are no additional points for implementing both the selection sort and merge sort.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

Find z ds, where C is the line segment from (0,-6,-2) to (4,-9,-7).

Answered: 1 week ago

Question

4. Choose appropriate and powerful language

Answered: 1 week ago

Question

2. Choose an appropriate organizational pattern for your speech

Answered: 1 week ago