Created
February 5, 2017 14:38
-
-
Save 13andrew13/dec3e4aa3bb736df736a2627fb459e97 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public interface Data { | |
public int getsize(); | |
public String toString(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class DataRunner { | |
public static void main(String[] args) { | |
Directory directory = new Directory(); | |
directory.add(new File(10)); | |
Directory directory1 = new Directory(); | |
directory.add(directory1); | |
directory1.add(new File(20)); | |
directory1.add(new File(40)); | |
Directory directory2 = new Directory(); | |
directory1.add(directory2); | |
directory1.add(new File(20)); | |
System.out.println(directory.toString()); | |
System.out.println("Size of directory "+directory.getsize()); | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Directory implements Data { | |
private ArrayList<Data> files = new ArrayList<Data>(); | |
public Directory(){ | |
} | |
public void add(Data data){ | |
files.add(data); | |
} | |
public int getsize(){ | |
int size = 0; | |
for(Data file: files){ | |
size += file.getsize(); | |
} | |
return size; | |
} | |
public String toString(){ | |
String name="d["; | |
for(Data data:files){ | |
name +=data.toString(); | |
} | |
return name+"] "; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class File implements Data { | |
private int size; | |
public File(int size) { | |
this.size = size; | |
} | |
public int getsize(){ | |
return size; | |
} | |
public String toString(){ | |
return "f(" + size + ") "; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment