Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

You are given the following Filesystem representation: My Docs S u b The filesys

ID: 3710580 • Letter: Y

Question

You are given the following Filesystem representation: My Docs S u b The filesystem is internally represented by a single linked list that tells the operating system where to find the files in disk The data member "Data" holds the location of the file on disk, null for directories. "Size" refers to the size of the file on disk. Type" is a 4 character string holding the extension of the file, "DIR" for directories. "Next" is a reference to the next file or directory inside the same folder. "Sub" is a reference to the contents of a folder, null for files or empty folders. Imp_Docs Other Dos The field "Size" holds the size of a file on disk, in bytes. For directories, the variable "Size" contains the addition of the sizes of all ts contents. Every time a folder is opened by a user the to Write a method for calculating the size of a folder by following the requirements below: (5 Marks) . Use a recursive approach . Use the header private long TreeSize(node dir) . As an initial implementation, assume the parameter is always correct a) If a folder is empty its size is zero

Explanation / Answer

//if you any doubt write to me in comment section....if this is helpful give positive feedback... private long TreeSize(node dir) { if (dir.isFile() && dir.canRead()) { return dir.length(); } long size = 0; System.out.println(dir.toString()); File[] tmp = dir.listFiles(); if ( tmp != null ) {/*if size is not null....if it is null then it directly go to return statement and return size which is initially zero....*/ for (File file : dir.listFiles()) { // NPE gone if (file.isFile()) size += file.length(); else size += calcSize(file); } } return size; }

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote