Results 1 to 2 of 2
  1. #1
    elliotHenry is offline Member
    Join Date
    Mar 2011
    Posts
    34
    Rep Power
    0

    Default Thought I'd try again

    Apologies for posting this again, but my other thread hasn't had any response tonight. I'm assuming it's because it's a little long. Here's my new issue. Once again any help would be appreciated (and thanks to those that helped out the last time, I think I solved the problem) Anyway, down to the new issues, here's my code
    Java Code:
    import java.util.*;
    public class FishFarm
    {
       private Map<String, List<Fish>> findFish;
       public FishFarm()
    
       {
         //Map<String, List<Fish>> findFish = new HashMap<String, List<Fish>>();
        findFish = new HashMap<String, List<Fish>>();
       }
       public void fish()   
       {
               
          Set<String> key = findFish.keySet();
          for (String eachFish : key)
          {
             this.findFish.get(eachFish).printString(); 
           }
    
        }  
       public void addFish()
       {
          List<Fish> temp;
          temp = new ArrayList<Fish>();
          temp.add(new Fish("Shark", "Salt Water",20));
          this.findFish.put("Shark", temp);      
          this.findFish.get("Shark").add(new Fish("Shark", "Salt Water",20));
          temp = new ArrayList<Fish>();
          temp.add(new Fish("Perch", "Fresh Water",2));
          this.findFish.put("Perch", temp);      
          this.findFish.get("Perch").add(new Fish("Perch", "Fresh Water",2));
          temp = new ArrayList<Fish>();
          temp.add(new Fish("Shark", "Fresh Water",22));
          this.findFish.put("Shark", temp);      
          this.findFish.get("Shark").add(new Fish("Shark", "Fresh Water",22));
          
       }
    
    }
    Problem is with this line

    Java Code:
    this.findFish.get(eachFish).printString();
    printString is a method that belongs to the class Fish. My fish objects are now stored in the list which is part of the map. I now need to figure out how to drill down another level (i.e. what's missing between "this.findFish.get(eachFish)" and "printString()"), that will allow me to execute the method on the object.

    Thanks

  2. #2
    elliotHenry is offline Member
    Join Date
    Mar 2011
    Posts
    34
    Rep Power
    0

    Default Never mind

    Hi folks. Don't worry, I think I've sused it. Cheers

Similar Threads

  1. **** Penny for a thought ****
    By dododidi in forum New To Java
    Replies: 5
    Last Post: 03-24-2009, 01:12 AM
  2. Learning java is harder than I thought.
    By 2ndis1stplaceloser in forum Introductions
    Replies: 1
    Last Post: 10-21-2008, 01:52 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •