title: Extract 3 substrings and create Animal Object
body: <p>I am currently working on my '<strong><code>readDataFromFile()</code></strong>' method which reads texts files such as:</p>
  
  <pre><code>Bird    Golden Eagle    Eddie
  Mammal  Tiger   Tommy
  Mammal  Lion    Leo
  Bird    Parrot  Polly
  Reptile Cobra   Colin
  </code></pre>
  
  <ul>
  <li><p>How would I go about extracting <strong><code>3 substrings</code></strong> and then create and add an <strong><code>Animal object</code></strong> to the <strong><code>Zoo</code></strong>.</p></li>
  <li><p>An Animal object has: name and species.</p></li>
  </ul>
  
  <p>I have 2 classes: <code>Zoo and Animal</code>. Any help on this subject would be amazing.</p>
  
  <p>Zoo Class: </p>
  
  <pre><code>public class MyZoo
  {
     private String zooId;
     private int nextAnimalIdNumber;
     private TreeMap&lt;String, Animal&gt; animals;
     private Animal animal;
  
     public MyZoo(String zooId)
     {
        this.zooId = zooId.trim().substring(0,3).toUpperCase();
        nextAnimalIdNumber = 0;
        animals = new TreeMap&lt;String, Animal&gt;();
     }
  
     public void addAnimal(Animal animal)
     {
        animals.put(animal.getName(), animal);
        this.animal = animal;
     }
  
     public void readDataFromFile() throws FileNotFoundException
     {
        int noOfAnimalsRead = 0;
  
        String fileName = null;
  
        JFrame mainWindow = new JFrame();
        FileDialog fileDialogBox = new FileDialog(mainWindow, "Open", FileDialog.LOAD);
        fileDialogBox.setDirectory("."); 
        fileDialogBox.setVisible(true);
  
        fileName = fileDialogBox.getFile();
        String directoryPath = fileDialogBox.getDirectory();
  
        File dataFile = new File (fileName);
        Scanner scanner = new Scanner(dataFile);
  
        scanner.next();
        while(scanner.hasNext())
         {
         String name = scanner.nextLine();
         System.out.println("Animal: " + name);
         }
  
        scanner.close();
     }
  </code></pre>
  
  <p>Animal Class:</p>
  
  <pre><code>public class Animal
  {
     private String id;
     private String species;
     private String name;
     public Animal(String species, String name, MyZoo owner)
     {
        id = owner.allocateId();
        this.species = species;
        this.name  = name;
     }
  
     public String getId()
     {
        return id;
     }
  
     public String getName()
     {
        return name;
     }
  
     public String getSpecies()
     {
        return species;
     }
  
     public String toString()
     {
        return id + "  " + name + ": a " + species;
     }
  }
  </code></pre>