Question 0
Le code compile et affiche 2,0,0,B,A
Question 1
interface SystemElement{
abstract String getDescription();
abstract boolean open();
}
abstract class Element implements SystemElement{
String name;
Directory parent;
Element(String n, Directory d) throws java.lang.IllegalArgumentException{
if(d.containsElement(n)) throw new java.lang.IllegalArgumentException("Name
already used in the directory");
else{
this.name = n; this.parent = d;
}
}
abstract int getSize();
}
class Directory extends Element{
java.util.LinkedList<Element> children;
Directory(String n, Directory d) throws java.lang.IllegalArgumentException{
super(n,d);
this.children = new java.util.LinkedList<Element>();
}
boolean containsElement(String n){
for(Element e:this.children){
if(e.name.equals(n)) return true;
}
return false;
}
boolean mkdir(String n){
try{
Directory d = new Directory(n,this);
this.children.add(d);
return true;
}
catch(java.lang.IllegalArgumentException e){return false;}
}
boolean touch(String n){
try{
TextFile f = new TextFile(n,this,0);
this.children.add(f);
return true;
}
catch(java.lang.IllegalArgumentException e){return false;}
}
int getSize(){
int s = 0;
for(Element e:this.children) s += e.getSize();
return s;
}
boolean addFile(File f){
if(this.containsElement(f.name)) return false;
else{
this.children.add(f);
return true;
}
}
public String getDescription(){
return this.name + ":" + this.getSize() + ":" + this.children.size();
}
public boolean open(){
for(Element e:this.children){