COMP 1671 , Fall 2006

LAB 8

  1. Design and create an animal class to be used in a zoo. Your class should store the following information: species, age, height, weight, gender, and name (zoos like to give animals names to build a tie between the public and the animals). Your class should include public get/set methods for each member, a constructor, a print method, and a Mate() method. The mate method should take as an argument another animal object and simply print out whether the two objects are allowed to mate. They are allowed to mate if they are the species and of different genders. Later we will modify the Mate() method to return a new animal object.

    There is no graphical component to this exercise. Objects do NOT need to be on the screen, they exist in the abstract also.

  2. Create a zoo full of animals. Write a program that creates 40 animals and puts them in array. Use random number generation to set all the fields. For the species and name members, create an array of 5 species and an array of 20 names, then generate a random integer, 0..9, to use as an offset within these arrays to get names. Once created, loop through your array and print out all pairs of animals that are potential mates.

    Note, to help, you might find the following code example useful for generating random names:

    var rNum:Number ;   // holds a random number
    var rName:String ;   // holds a name chosen randomly from the name array
    
    // create an array and fill it with 5 names
    var nameArray:Array = ["bob","sue","tom","mary","heather"] ;
    
    // code to get a random name from the array:
    rNum = Math.floor( Math.random() * 5 ) ;
    rName = nameArray[rNum] ;
    trace(rName) ;