Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

in java, without using streams please solve . You are designing a directory structure for a file system. Each directory can contain files and subdirectories.

in java, without using streams please solve .You are designing a directory structure for a file system. Each directory can contain
files and subdirectories. Write a recursive function calculateTotalSize that takes a
Directory object as input and returns the total size (in bytes) of all files within the
directory and its subdirectories.
The Directory and File classes are defined as follows:
1 class Directory {
2 private String name ;
3 private List < File > files ;
4 private List < Directory > subdirectories ;
5
6 public List < File > getFiles (){
7 return files ;
8}
9
10 public List < Directory > getSubdirectories (){
11 return subdirectories ;
12}
13}
14
15 class File {
16 private String name ;
17 private int size ; // Size in bytes
18
19 public int getSize (){
20 return size ;
21}
22}

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

Managing Your Information How To Design And Create A Textual Database On Your Microcomputer

Authors: Tenopir, Carol, Lundeen, Gerald

1st Edition

1555700233, 9781555700232

More Books

Students also viewed these Databases questions