Exercise 1:

The target of this exercise is to practice with hash tables. We are going to create some objects that will be stored in and retrieved from a hash table.

First, we are going to create a class, called Mouse, to identify the mouses used in a genetic reseach laboratory. This class will have these variables:

Write a test program that:

  1. Creates a hash table and fill it with mouse objects. Use the cdg field as the hash key.

  2. Locates one existing mouse in the hast table, and prints the result.

  3. Tries to locate a mouse in the table after deleting it.

  4. Prints information about the hash table: number of elements stored, its content, etc.

  5. Gets a enumeration class from the hash table and prints all its elements.

  6. Prints all the ancestors of a given mouse. Write a method, called Ancestors, to make this operation.


Exercise 2:

The target of this exercise is to practice with the java.util.Vector class.

Modify the program developed in the exercise 1 to include a new method to calculate the genealogic history of a mouse.

The genealogic history of a mouse is a vector containing the codes of all its ancestors in the following order:

  1. mouse code.
  2. code of the father.
  3. code of the mother.
  4. code of the father of the father.
  5. code of the father of the mother.
  6. code of the mother of the father.
  7. code of the mother of the mother.
  8. etc.
until no more information is available. Unknown positions should be identified with a question string, "?".

Then, if we don't know who the mouse parents are, the genealogic history is a vector with only one value, the mouse code.

If we only know who the father and the mother of the mouse are, the genealogic history is a vector with only three values, the mouse code, the father code and the mother code.

In general, the genealogic history of a mouse is calculated mixing the genealogic history of its father with the genealogic history of its mother, taking one value alternatively from each of them.

Write a method, called GenHistory, which returns a vector with the genealogic history of a given mouse.

Include this method in the exercise 1 and test it.

Execution example: filling the hash table with these mouses:

Mouse(m42,Jacinta,white,m31,m32)
Mouse(m41,Segundo,white,m31,m32)
Mouse(m18,Teresa,white,null,null)
Mouse(m17,Apolinar,white,null,null)
Mouse(m16,Anastasia,white,null,null)
Mouse(m15,Eugenio,white,null,null)
Mouse(m14,Maria,white,m01,m02)
Mouse(m13,Damian,white,null,null)
Mouse(m12,Paula,white,null,null)
Mouse(m11,Gabriel,white,null,null)
Mouse(m34,Juan,white,m26,m25)
Mouse(m33,Pedro,white,m23,m24)
Mouse(m32,Laura,white,m23,m24)
Mouse(m31,Felipe,white,m21,m22)
Mouse(m02,Candida,white,null,null)
Mouse(m01,Santiago,white,null,null)
Mouse(m27,Fernanda,white,m13,m14)
Mouse(m26,Serapio,white,m13,m14)
Mouse(m25,Heliodora,white,m11,m12)
Mouse(m24,Manuela,white,m17,m18)
Mouse(m23,Felix,white,m15,m16)
Mouse(m22,Delfina,white,m13,m14)
Mouse(m21,Gregorio,white,m11,m12)
the genealogic history of m41 must be:
m41, m31, m32, m21, m23, m22, m24, m11, m15, 
m13, m17, m12, m16, m14, m18,   ?,   ?,   ?,
  ?,   ?,   ?, m01,   ?,   ?,   ?,   ?,   ?,
  ?,   ?, m02