Logout

May 2014 Genus & Species


Genus.java
1    package may2014_genus_species; 
2     
3    public class Genus { 
4        private String genusName; 
5     
6        public Genus(){ 
7     
8        } 
9     
10       public Genus(String genusName){ 
11           this.genusName = genusName; 
12       } 
13    
14       public String getGenusName() { 
15           return genusName; 
16       } 
17   } 
18   
Species.java
1    package may2014_genus_species; 
2     
3    public class Species extends Genus{ 
4     
5        private String speciesName; 
6     
7        public Species( String s, String g ) 
8        { 
9            super(g); 
10           setSpeciesName(s); 
11       } 
12    
13       public void setSpeciesName(String s){ speciesName = s; } 
14    
15       public String getSpeciesName(){ return speciesName; } 
16    
17       public String toString() 
18       { 
19           return "Species: " + getGenusName() + " " + speciesName; 
20       } 
21    
22       public boolean equals(Species s) 
23       { 
24           return speciesName.equals(s.getSpeciesName()); 
25       } 
26   } 
27   
Specimen.java
1    package may2014_genus_species; 
2     
3    public class Specimen 
4    { 
5        private String name; 
6        private int cageNumber; 
7        private Species toa; // "Type Of Animal" 
8     
9        public Specimen(String a, int c, Species s) { 
10           setName(a); 
11           setCage(c); 
12           setTOA(s); 
13       } 
14    
15       public void setName(String a){ name = a; } 
16    
17       public void setCage(int c){ cageNumber = c; } 
18    
19       public void setTOA(Species s){ toa = s; } 
20    
21       public String getName(){ return name; } 
22    
23       public int getCage(){ return cageNumber; } 
24    
25       public Species getTOA(){ return toa; } 
26    
27       public String toString() 
28       { 
29           return name + " is a " + toa + " in cage " + cageNumber; 
30       } 
31   } 
32   
MainForMay2014.java
1    package may2014_genus_species; 
2     
3    import java.util.LinkedList; 
4     
5    public class MainForMay2014 { 
6        public static void main(String[] args) { 
7            Species human = new Species ( "homo", "sapiens" ); 
8            System.out.println( human.toString() ); 
9        } 
10    
11       //Post conditions: output the number of specimens of the given species in the zoo. 
12       public void countSpecimens( Specimen[] animals, Species s ){ 
13           //To Do 
14       } 
15    
16       //Post conditions: will generate a list of the different species in the zoo. 
17       public void listSpecies( Specimen[] animals ){ 
18           //To Do 
19       } 
20    
21       public LinkedList makeList(Specimen[] animals ) 
22       { 
23           // insert your code here 
24           return new LinkedList<Species>();//for now just to take away the return red squiggly 
25       } 
26   } 
27