title: UML diagram to Java code
body: <p>I'm new to Java and am trying to work through some questions where I have to convert a UML diagram to Java code: I have an image of the uml document-</p>
  
  <p><a href="http://s1079.photobucket.com/albums/w513/user20121/?action=view&amp;current=uml.jpg" rel="nofollow noreferrer">http://s1079.photobucket.com/albums/w513/user20121/?action=view&amp;current=uml.jpg</a></p>
  
  <p>I'll show you what I have so far:</p>
  
  <p>Q1: Write a Java version of class Entry assuming it has this constructor: public Entry(String name) and that the method getSize is abstract.
  A:</p>
  
  <pre><code>public abstract class Entry {
      private String name;
  
      public Entry(String name){
          this.name =  name;
      }
      public String getName()
      {
          return name;
      }
      abstract long getSize();
  }
  </code></pre>
  
  <p>Q2: Write a Java version of class File assuming it has this constructor:
  public File(String name, long size)
  A:</p>
  
  <pre><code>public class File extends Entry {
      private long size;
  
      public File(String name, long size){
          super(name);
          this.size = size;
      }
  
      public long getSize(){
          return size;
      }
  }
  </code></pre>
  
  <p>Q3: A directory contains a collection of files and directories. Write a Java version of class Directory assuming it has this constructor:
  public Directory(String name) and the method getSize returns the total size of all the files in the directory and all its
  sub-directories (in this model the size of a directory itself is ignored).</p>
  
  <p>A: This is where I get stuck, I don't know what to do about the getSize method. Can anyone tell me whether what I have done so far is correct? And also point me in the right direction for Q3?</p>
  
  <p>Edit: okay I have attempted an answer but I really I don't know what I'm doing..</p>
  
  <pre><code>import java.util.ArrayList;
  
  public class Directory extends Entry {
  
      ArrayList &lt;Entry&gt; entries = new ArrayList&lt;Entry&gt;();
  
      public Directory(String name)
      {
          super(name);
      }
  
      public long getSize(){
          long size;
          for(int i=0;i&lt;entries.size();i++)
          {
          size +=  //don't know what to put here?
          }
          return size;
      }
  }
  </code></pre>