Link to home
Start Free TrialLog in
Avatar of Slck_P
Slck_P

asked on

Using ArrayList and Extends

I'm trying to set up my arraylist in my Animal class but should it be in my AnimalDisplayList instead?  Also if I'm trying to get the type of Bird through the Bird class should I set the static variables to ints so that the user can just get a #?  Also I've used ints in my animal class for size but I don't know If i've stated them correctly.  I'm also getting errors on my ENUM but I don't really understand why...  Is enum supposed to be in a class by itself?  Any help is appreciated.    Here are the errors I'm getting:  

Animal.java:38: ',', '}', or ';' expected
         BEAGLE = 0,
                ^
Animal.java:38: '}' expected
         BEAGLE = 0,
                 ^
Animal.java:39: <identifier> expected
                  PITBULL = 1;
                         ^
Animal.java:40: <identifier> expected
                  LABRADOR = 2;
                          ^
etc...


    public class AnimalListDisplay extends JList
   {
   
       public AnimalListDisplay()
      {
      }
       public void sortAge()
      {
      }
       public void filterAge()
      {
      }
   
       public void sortID()
      {
      }
       public void filterID()
      {
      }
   
   
       public void sortSpecialNeeds()
      {
      }
   
   
       public void filterSpecialNeeds()
      {
      }
   
       public void sortDescription()
      {
      }
   
   
       public void filterDescription()
      {
      }
   
       public void sortSize()
      {
      }
       public void filterSize()
      {
      }
   
   }

    public class Bird extends Animal
   {
      public static final String PARROT;
      public static final String OUTDOOR;
      public static final String SMALL;
   
       public Bird()
      {
         super(aniID, aniAge, aniSize, aniNeeds, animalDesc);
     
         String type;
         
            
         
            
     
      }
   }
public abstract class Animal 
   {
      protected int id;
      protected int age;
      protected int size;
      protected String needs;
      protected String description;
		public static final int GIANT = 1;
		public static final int LARGE = 2;
		public static final int MEDIUM = 3;
		public static final int SMALL = 4; 
		public static final int MINIATURE = 5;
		public static final int CATSIZE = 6;
		public static final int BIRDSIZE = 7;
   
       public Animal()
      {
         id = 0;
         age = 0;
         size = 0;
         needs = ("");
         description = ("");
      
      
      }
   
       public Animal(int aniId, int aniAge, int aniSize, String aniNeeds, String animalDesc)
      {
         this.id = aniId;
         this.age = aniAge;
         this.size = aniSize;
         this.needs = aniNeeds;
         this.description = animalDesc;
      }
		
		   public enum setSize
		       {
         BEAGLE = 0,
			PITBULL = 1;
			LABRADOR = 2;
		   BULLDOG = 3;
   GREYHOUND = 4;
    LOVEBIRD = 5;
  MACAW = 6;
   ROBIN = 7;
   CHICKEN = 8;
     GOLDENEAGLE = 9;
     TABBY = 10;
     SIAMESE = 11;
      SINGAPURA = 12;
     BURMESE = 13;
     SPHYNX = 14;


      }
   	public void setAnimal(AnAnimal type)
	
   	{
		
		
   	
   // 	int 00000 = dog1;
//    	int 00001;
//    	int 00002;
//    	int 00003;
//    	int 00004;
//    	int 00005;
//    	int 00006; 
//    	int 00007;
//    	int 00008;
//    	int 00009;
//    	int 00010;
//    	int 00011;
//    	int 00012;
//    	int 00013;
//    	int 00014;
//    	int 00015;
   	
//    	ArrayList < Animal > list = new ArrayList<Animal>;
   	
   	
		}
    			
      
      
     // ArrrayList <Dog> dogSize = new ArrayList<Dog>
      //dogSize.add(5);
      
      
      
      }
       public int getSize()
      {
      
         return size;
      }
      
          
   }

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of robthewolf
robthewolf
Flag of Israel image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Slck_P
Slck_P

ASKER

Sorry here's the updated code:


import java.util.ArrayList;
   
   
    public abstract class Animal 
   {
   
   
      // protected int id;
      // protected int age;
      // protected int size;
      // protected String needs;
      // protected String description;
      // public static final int GIANT = 1;
      // public static final int LARGE = 2;
      // public static final int MEDIUM = 3;
      // public static final int SMALL = 4; 
      // public static final int MINIATURE = 5;
      // public static final int CATSIZE = 6;
      // public static final int BIRDSIZE = 7;
      private AnimalType id = null;
      private int age = 0;
      private int size = 0;
      private String needs = "";
      private String description = "";
      
      
       public Animal()
      {
              
      }
   
       public Animal(int aniId, int aniAge, int aniSize, String aniNeeds, String animalDesc)
      {
         this.id = aniId;
         this.age = aniAge;
         this.size = aniSize;
         this.needs = aniNeeds;
         this.description = animalDesc;
      }
   	
   	 	
       enum AnimalType
      { 
         BEAGLE,
         PITBULL,
         LABRADOR,
         BULLDOG,
         GREYHOUND,
         LOVEBIRD,
         MACAW,
         ROBIN,
         CHICKEN,
         GOLDENEAGLE,
         TABBY,
         SIAMESE,
         SINGAPURA,
         BURMESE,
         SPHYNX,
      }   	
      
       public AnimalType getId() {
       
         return id;
      }
       public void setId()
      {
         this.id = id;
      }
       public int getSize(int size)
      {
         return size;
      
      }
       public void setSize()
      {
         this.size = size;
      }
      
       public String getNeeds(String needs)
      {
         return needs;
      }
   	
       public void setNeeds()
      {
         this.needs = needs;
      }
   
       public String getDescription(String description)
      {
         return description;
      }
   
       public void setDescription()
      
      {
         this.description = description;
      }
   
      
       public int getBreed()
      {
         return breed;
      }
      
        
       public void setAnimal(AnAnimal type)
      
      {
      
      
      
      // 	int 00000 = dog1;
      //    	int 00001;
      //    	int 00002;
      //    	int 00003;
      //    	int 00004;
      //    	int 00005;
      //    	int 00006; 
      //    	int 00007;
      //    	int 00008;
      //    	int 00009;
      //    	int 00010;
      //    	int 00011;
      //    	int 00012;
      //    	int 00013;
      //    	int 00014;
      //    	int 00015;
      
      //    	ArrayList < Animal > list = new ArrayList<Animal>;
      
      
      
      		
      
      
      // ArrrayList <Dog> dogSize = new ArrayList<Dog>
      //dogSize.add(5);
      
      
      
      }      
          
   }

Open in new window

The animal class is an abstract class representing a single animal. It should not have an arraylist in it.
Avatar of Slck_P

ASKER

OK.  If I used the following format with Breed(ID#) would I need to call this in the constructor of Animal?  


import java.util.ArrayList;
   
   
    public abstract class Animal 
   {
   
   
      // protected int id;
      // protected int age;
      // protected int size;
      // protected String needs;
      // protected String description;
      // public static final int GIANT = 1;
      // public static final int LARGE = 2;
      // public static final int MEDIUM = 3;
      // public static final int SMALL = 4; 
      // public static final int MINIATURE = 5;
      // public static final int CATSIZE = 6;
      // public static final int BIRDSIZE = 7;
      private AnimalType id = null;
      private int age = 0;
      private int size = 0;
      private String needs = "";
      private String description = "";
      
      
       public Animal()
      {
              
      }
   
       public Animal(int aniId, int aniAge, int aniSize, String aniNeeds, String animalDesc)
      {
         this.id = aniId;
         this.age = aniAge;
         this.size = aniSize;
         this.needs = aniNeeds;
         this.description = animalDesc;
      }
   	
   	 	
       enum AnimalType
      { 
         BEAGLE(001),
         PITBULL(011),
         LABRADOR(012),
         BULLDOG(013),
         GREYHOUND(014),
         LOVEBIRD(021),
         MACAW(022),
         ROBIN(023),
         CHICKEN(024),
         GOLDENEAGLE(025),
         TABBY(031),
         SIAMESE(032),
         SINGAPURA(033),
         BURMESE(034),
         SPHYNX(035),
      }   	
      
       public AnimalType getId() {
       
         return id;
      }
       public void setId()
      {
         this.id = id;
      }
       public int getSize(int size)
      {
         return size;
      
      }
       public void setSize()
      {
         this.size = size;
      }
      
       public String getNeeds(String needs)
      {
         return needs;
      }
   	
       public void setNeeds()
      {
         this.needs = needs;
      }
   
       public String getDescription(String description)
      {
         return description;
      }
   
       public void setDescription()
      
      {
         this.description = description;
      }
   
      
       public int getBreed()
      {
         return breed;
      }
      
        
       public void setAnimal(AnAnimal type)
      
      {
      
      
      
      // 	int 00000 = dog1;
      //    	int 00001;
      //    	int 00002;
      //    	int 00003;
      //    	int 00004;
      //    	int 00005;
      //    	int 00006; 
      //    	int 00007;
      //    	int 00008;
      //    	int 00009;
      //    	int 00010;
      //    	int 00011;
      //    	int 00012;
      //    	int 00013;
      //    	int 00014;
      //    	int 00015;
      
      //    	ArrayList < Animal > list = new ArrayList<Animal>;
      
      
      
      		
      
      
      // ArrrayList <Dog> dogSize = new ArrayList<Dog>
      //dogSize.add(5);
      
      
      
      }      
          
   }

Open in new window

SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.