Lab 7: Hash Tables (100 pts)

Due Monday, May 27 at 11:59pm on Canvas


Pair Programming Required or No Credit!

  • Both partners fill in, sign and date the pair programming contract and BOTH partners submit.
  • Only ONE partner submits the lab assignment on Canvas. Please make sure both your names are on ALL the files.

Part 1: Complete the Butterfly Class (10 pts)

  • Copy and paste the below code into a file named Butterfly.java.
  • Fill in the missing method bodies to override equals, and hashCode and implement compareTo for a Butterfly object, as described in the comments for these methods.
  • Note: Please do not alter this file in any way or you may not receive credit for this Lab. You must only add to it.
/**
 * Butterfly class
 * @author
 * @author
 * CIS 22C, Lab 7
 */

public class Butterfly implements Comparable<Butterfly>{
    private String family;
    private String species;
    private String color;
    private int speciesNumber;
    private static int speciesNum = 550;
   
    /**
     * Default constructor for Butterfly
     * Assigns the following default values
     * family: "Family unknown"
     * species: "Species unknown"
     * color: "Color unknown"
     * speciesNumber: 0
     * Hint: call this(family, species, color)!
     */
   
    public Butterfly() {
           
    }
   
    /**
     * Two-argument constructor for Butterfly
     * @param family the family of butterfly
     * @param species the butterfly species
     * color assigned to "Color unknown"
     * speciesNumber assigned to 0
     * Hint: call this(family, species, color)!
     */
    public Butterfly(String family, String species) {
       
    }
   
    /**
     * Multi-argument constructor for Butterfly
     * @param family the family of butterfly
     * @param species the butterfly species
     * @param color the principle wing color
     * speciesNumber assigned to 0
     */
    public Butterfly(String family, String species, String color) {
       
    }
   
    /**
     * Creates a new butterfly that is a copy
     * of b. Except speciesNumber is assigned 0
     * @param b another Butterfly
     */
    public Butterfly(Butterfly b) {
       
    }
   
    /**
     * Accesses the family of butterfly
     * @return the family of butterfly
     */
    public String getFamily() {
        return null;
    }
   
    /**
     * Accesses the species of butterfly
     * @return the species of butterfly
     */
    public String getSpecies() {
        return null;
    }
   
    /**
     * Accesses the color of butterfly
     * @return the color of butterfly
     */
    public String getColor() {
        return null;
    }
   
    /**
     * Accesses the assigned species number
     * @return the species number
     */
    public int getSpeciesNumber() {
        return 0;
    }
   
    /**
     * Assigns a new family of butterfly
     * @param family the butterfly family
     */
    public void setFamily(String family) {
       
    }
   
    /**
     * Assigns a new species of butterfly
     * @param species the butterfly species
     */
    public void setSpecies(String species) {
       
    }
   
    /**
     * Assigns a new color of butterfly
     * @param color the principle wing color
     */
    public void setColor(String color) {
       
    }
   
    /**
     * Assigns a new species number
     * @param speciesNumber the number generated
     * by generateSpeciesNumber variable
     */
    public void setSpeciesNumber(int speciesNumber) {
       
    }
   
    /**
     * Used to generate a new species number
     * for each butterfly. To be called
     * each time a new buttefly object is
     * created (constructor is called).
     * Increments speciesNum and returns
     * this number
     * @return the species number
     */
    public static int generateSpeciesNumber() {
       
    }
   
    /**
     * Creates a String of butterfly information
     * Species: <species>
     * Family: <family>
     * Color: <color>
     * Species Number <speciesNumber>
     * @return the butterfly information
     */
    @Override public String toString() {
        return "";
    }
   
    /**
    * Returns whether two Buttefly objects
    * Have the same family and species (only)
    */
    @Override public boolean equals(Object o) {
        return false;
    }
   
    /**
     * Returns a consistent hash code for
     * each Butterfly by summing the Unicode values
     * of each character in the key
     * key = family + species
     * @return the hash code
     */
    @Override public int hashCode() {
        String key = family + species;
        int sum = 0;
        for (int i = 0; i < key.length(); i++) {
            sum += (int) key.charAt(i);
        }
        return sum;
    }
   
    /**
    * Compares two Butterfly objects
    * Returns 0 if the two Butterfly objects
    * are equal. Otherwise, if the two
    * species are different, returns the String
    * compareTo value of this.species compared
    * to b.species. Otherwise, returns the compareTo
    * value of this.family compared to b.family
    */
    @Override public int compareTo(Butterfly b) {
        return 0;
    }
   
   
}

Part 2: Write the HashTable.java class (70 pts)


List.java

  • Recommended: Create a new Java project folder for Lab 7
    • Create a new List.java class inside this folder and copy and paste your List.java from Lab 4 into this folder.
  • You must use the Lab 4 List class as part of your Hash Table implementation
  • Note that the Hash Table class we write for this lab will use separate chaining to resolve collisions.
    • We will use List.java to store the chained data

HashTable.java

  • Create a second file called HashTable.java and copy and paste the below code into it.
  • Please do not alter HashTable.java in any way other than to implement the methods or you may not receive credit for this lab
  • Note that you are storing the values in an ArrayList of Lists.
  • Therefore, each index of the ArrayList is one linked list.
  • For most of these methods, you will be calling List.java methods
  • Try to call the methods you have already written for List.java rather than re-writing these methods
  • Remember that you have ways to search, insert at the end of a List, iterate through the nodes in a List, etc.
  • The challenge of this Lab will be to understand which List methods to call and to keep separate in your mind the ArrayList from the Lists stored inside the ArrayList
/**
 * HashTable.java
 * @author
 * @author
 * CIS 22C, Lab 7
 */
import java.util.ArrayList;
import java.util.NoSuchElementException;

public class HashTable<T extends Comparable<T>> {
    
    private int numElements;
    private ArrayList<List<T> > Table;

    /**
     * Constructor for the HashTable.java
     * class. Initializes the Table to
     * be sized according to value passed
     * in as a parameter
     * Inserts size empty Lists into the
     * table. Sets numElements to 0
     * @param size the table size
     */
    public HashTable(int size) {
       
        
    }
       
    /**Accessors*/
    
    /**
     * returns the hash value in the Table
     * for a given Object
     * @param t the Object
     * @return the index in the Table
     */
    private int hash(T t) {
       
    }
    
    /**
     * counts the number of elements at this index
     * @param index the index in the Table
     * @precondition 0 <=  index < Table.length
     * @return the count of elements at this index
     * @throws IndexOutOfBoundsException
     */
    public int countBucket(int index) throws IndexOutOfBoundsException{
        return 0;
    }
    
    /**
     * returns total number of elements in the Table
     * @return total number of elements
     */
    public int getNumElements() {
        return 0;
    }
    
    /**
     * searches for a specified element in the Table
     * @param t the element to search for
     * @return the index in the Table (0 to Table.length - 1)
     * or -1 if t is not in the Table
     */
    public int search(T t) {
        return -1;
    }
    
    
    /**Manipulation Procedures*/
    
    /**
     * inserts a new element in the Table
     * calls the hash method to determine placement
     * @param t the element to insert
     */
    public void insert(T t) {    
       
    }  
    
    
    /**
     * removes the element t from the Table
     * calls the hash method on the key to
     * determine correct placement
     * has no effect if t is not in
     * the Table
     * @param t the key to remove
     * @precondition t must be in the table
     * @throws NoSuchElementException when
     * the element is not in the table
     */
    public void remove(T t) throws NoSuchElementException{
       
    }

    /**Additional Methods*/

    /**
     * Prints all the keys at a specified
     * bucket in the Table. Each element displayed
     * on its own line, with a blank line
     * separating each element
     * Above the elements, prints the message
     * "Printing bucket #<bucket>:"
     * Note that there is no <> in the output
     * @param bucket the index in the Table
     * @throws IndexOutOfBoundsException
     */
    public void printBucket(int bucket)
throws IndexOutOfBoundsException{
       
    }
        
    /**
     * Prints the first element at each bucket
     * along with a count of the total elements
     * with the message "+ <count> -1 more
     * at this bucket." Each bucket separated
     * with to blank lines. When the bucket is
     * empty, prints the message "This bucket
     * is empty." followed by two blank lines
     */
    public void printTable(){
       
     } 
}

Starter Code for HashTableTest.java

  • Next, create a third Java file for this project called HashTableTest.java
  • Copy and paste the below code into this file.
  • Note that this test file is incomplete.
  • Important: You will need to add more tests to this file in order to test your HashTable.java thoroughly
import java.util.NoSuchElementException;

public class HashTableTest {
    public static void main(String[] args) {
        HashTable<Butterfly> ht = new HashTable<>(10); //make smaller than suggested by
        //rule-of-thumb for convenience-sake while testing. In ButterflyDatabase, let k = 2n to 3n
        Butterfly b1 = new Butterfly("Swallowtail" , "Zebra Swallowtail", "Black and white");
        b1.setSpeciesNumber(Butterfly.generateSpeciesNumber());
        Butterfly b2 = new Butterfly("Swallowtail" , "Western Tiger Swallowtail", "Yellow");
        b2.setSpeciesNumber(Butterfly.generateSpeciesNumber());
        Butterfly b3 = new Butterfly("Brush-footed Butterfly" , "Monarch", "Orange");
        b3.setSpeciesNumber(Butterfly.generateSpeciesNumber());
        Butterfly b4 = new Butterfly("Brush-footed Butterfly" , "Queen", "Orange");
        b4.setSpeciesNumber(Butterfly.generateSpeciesNumber());
        Butterfly b5 = new Butterfly("Brush-footed Butterfly" , "Julia Heliconian", "Orange");
        b5.setSpeciesNumber(Butterfly.generateSpeciesNumber());
        Butterfly b6 = new Butterfly("Pieridae" , "Cabbage White", "White");
        b6.setSpeciesNumber(Butterfly.generateSpeciesNumber());
        Butterfly b7 = new Butterfly("Brush-footed Butterfly" , "Red-Spotted Purple", "Purple");
        b7.setSpeciesNumber(Butterfly.generateSpeciesNumber());
        Butterfly b8 = new Butterfly("Pieridae" , "Checkered White", "White");
        b8.setSpeciesNumber(Butterfly.generateSpeciesNumber());
        Butterfly b9 = new Butterfly("Pieridae" , "Clouded Sulphur", "Yellow");
        b9.setSpeciesNumber(Butterfly.generateSpeciesNumber());
        Butterfly b10 = new Butterfly("Brush-footed Butterfly" , "Eastern Tailed-Blue", "Blue");
        b10.setSpeciesNumber(Butterfly.generateSpeciesNumber());
        
        ht.insert(b1);
        ht.insert(b2);
        ht.insert(b3);
        ht.insert(b4);
        ht.insert(b5);
        ht.insert(b6);
        ht.insert(b7);
        ht.insert(b8);
        ht.insert(b9);
        ht.insert(b10);
       
        System.out.println("***Testing Insert and PrintTable***\n");
       
        ht.printTable();
       
        System.out.println("***Testing PrintBucket***\n");
       
        ht.printBucket(4);
       
        System.out.println("***Testing CountBucket***\n");
        int count = ht.countBucket(4);
        System.out.println("There are " + count + " butterflies at bucket 4\n");
       
        System.out.println("***Testing Search***\n");
        int index = ht.search(b9);
        if (index != -1) {
            System.out.println(b9.getFamily() + ": " + b9.getSpecies() + " is stored in the table");
        } else {
            System.out.println(b9.getFamily() + ": " + b9.getSpecies() + " is not stored in the table");
        }
     
        System.out.println("\n***Testing Remove***\n");
        try {
            ht.remove(b9);
            System.out.println(b9.getFamily() + ": " + b9.getSpecies() + " has been removed\n");
            ht.printBucket(index);
        } catch (NoSuchElementException e) {
            System.out.println(b9.getFamily() + ": " + b9.getSpecies() + " is not stored in the table "
                    + "\nAnd thereforecannot be removed.\n");
        }
       
        index = ht.search(b9);
        if (index != -1) {
            System.out.println(b9.getFamily() + ": " + b9.getSpecies() + " is stored in the table");
        } else {
            System.out.println(b9.getFamily() + ": " + b9.getSpecies() + " is not stored in the table");
        }
    }
}


Output of HashTableTest.java


***Testing Insert and PrintTable***

Bucket: 0
This bucket is empty.


Bucket: 1
Species: Eastern Tailed-Blue
Family: Brush-footed Butterfly
Color: Blue
Species Number: 560

+ 0 more at this bucket


Bucket: 2
Species: Checkered White
Family: Pieridae
Color: White
Species Number: 558

+ 0 more at this bucket


Bucket: 3
This bucket is empty.


Bucket: 4
Species: Zebra Swallowtail
Family: Swallowtail
Color: Black and white
Species Number: 551

+ 1 more at this bucket


Bucket: 5
Species: Queen
Family: Brush-footed Butterfly
Color: Orange
Species Number: 554

+ 0 more at this bucket


Bucket: 6
Species: Julia Heliconian
Family: Brush-footed Butterfly
Color: Orange
Species Number: 555

+ 1 more at this bucket


Bucket: 7
Species: Western Tiger Swallowtail
Family: Swallowtail
Color: Yellow
Species Number: 552

+ 1 more at this bucket


Bucket: 8
This bucket is empty.


Bucket: 9
Species: Cabbage White
Family: Pieridae
Color: White
Species Number: 556

+ 0 more at this bucket


***Testing PrintBucket***

Printing bucket #4:

Species: Zebra Swallowtail
Family: Swallowtail
Color: Black and white
Species Number: 551


Species: Clouded Sulphur
Family: Pieridae
Color: Yellow
Species Number: 559


***Testing CountBucket***

There are 2 butterflies at bucket 4

***Testing Search***

Pieridae: Clouded Sulphur is stored in the table

***Testing Remove***

Pieridae: Clouded Sulphur has been removed

Printing bucket #4:

Species: Zebra Swallowtail
Family: Swallowtail
Color: Black and white
Species Number: 551


Pieridae: Clouded Sulphur is not stored in the table


Calling the Hash Method

  • For the purposes of this assignment, we will be using the algorithm defined in class which sums the Unicode values of all the characters in the key and scales the result to indices of the table.
  • This algorithm is divided into two methods - hashCode (Note: overridden in the Butterfly.java class) and hash (written in the HashTable.java class)


Adding Values to the Hash Table

  • One of the first methods to write for any class is insertion.
  • Since we are using separate chaining for collision resolution, our table consists of an ArrayList where each index stores a List
  • Each time we insert a new element into the table, we need to complete these steps:
  1. Call the hash method to determine at which index or bucket to place the element inside the table
  2. Insert the element at the end of the chain at the appropriate index in the ArrayList
  3. Note that you need to call the correct method from the List class to insert this element onto the end of the chain.
  4. Each time you insert a new element, it should be added onto the end of the chain. There is no additional sorting required (or needed).


Printing Using printBucket:

  • To verify your Hash Table methods are working properly, you need to be able to print the elements contained in the Table.
  • Therefore, your next step - after writing insert - should be to write a print method.
  • There are two print methods you need to write for this lab - printBucket and printTable
  • printBucket is used to display all of the values stored in a single bucket (a "row" in the table).
  • The printBucket method will allow us to dig more deeply into what is contained at a particular bucket.
  • For example, a call to printBucket(4); in HashTest.java should display the following (assuming you have inserted the values provided above).


Printing bucket #4:

Species: Zebra Swallowtail
Family: Swallowtail
Color: Black and white
Species Number: 551


Species: Clouded Sulphur
Family: Pieridae
Color: Yellow
Species Number: 559


Printing the Hash Table Using printTable

  • The printTable method displays the first value stored at all indices in the table.
    • Note that it does not display all elements in the table.
  • You can think of printTable as providing a vertical cross section of values in the Table (whereas printBucket gives a horizontal cross section.)
  • If you are following along with my example for HashTest.java, we want the printTable method to print the following to the console given the values we have already inserted:

Bucket: 0
This bucket is empty.


Bucket: 1
Species: Eastern Tailed-Blue
Family: Brush-footed Butterfly
Color: Blue
Species Number: 560

+ 0 more at this bucket


Bucket: 2
Species: Checkered White
Family: Pieridae
Color: White
Species Number: 558

+ 0 more at this bucket


Bucket: 3
This bucket is empty.


Bucket: 4
Species: Zebra Swallowtail
Family: Swallowtail
Color: Black and white
Species Number: 551

+ 1 more at this bucket


Bucket: 5
Species: Queen
Family: Brush-footed Butterfly
Color: Orange
Species Number: 554

+ 0 more at this bucket


Bucket: 6
Species: Julia Heliconian
Family: Brush-footed Butterfly
Color: Orange
Species Number: 555

+ 1 more at this bucket


Bucket: 7
Species: Western Tiger Swallowtail
Family: Swallowtail
Color: Yellow
Species Number: 552

+ 1 more at this bucket


Bucket: 8
This bucket is empty.


Bucket: 9
Species: Cabbage White
Family: Pieridae
Color: White
Species Number: 556

+ 0 more at this bucket


  • In other words, for each bucket in the table, we are going to output the following to the console:
Bucket <index>
Species: <species>
Family: <family>
Color: <color>
Species Number: <speciesNumber>

+<#> more at this bucket

  • Also, please note that there are no <> around the output. The <> are conventionally used to mean fill in the blank. You should get used to this convention as you will likely see it again in future computer science classes.


Counting items at a bucket using the countBucket method

  • For this method, you will need to count the number of elements at a specific index or bucket.
  • Note that this method is a helper to printTable, which provides a tally of how many elements are stored at each index as part of its output (see above).

int count = ht.countBucket(4);
System.out.println("There are " + count + " butterflies at bucket 4\n");

//Output:

There are 2 butterflies at bucket 4


Searching the Table

  • Our search method will search for a particular element to determine at which bucket it is stored in the Table.
  • The first step will be to call the hash method to determine which index the element would be hashed to.
  • Next, you will need to search through the values at this bucket to determine if the element is stored at that bucket.
  • If you find the element, return the bucket or index (important: not the index in the linked list!).
  • If the element is not in the table, your method should return -1.
  • Note that you can use one of your List methods to complete this search. Which one is a better choice for a linked list search?


Removing a Butterfly from the Table

  • To remove an element, you will need to complete these steps:
    • Pass the object to the hash method to determine at which index this object is located (if in the table).
    • Search for the element in the chain at that bucket
    • Once you have located it, call the appropriate List removal method to remove the element from that bucket.
    • If the element is not found, throw a NoSuchElementException



Part 3: ButterflyDatabase.java (20 pts)


Text File: butterfly.txt

  • In Eclipse, right click the name of your project
  • Go to File-> New -> File and name your file butterfly.txt
  • Note that this file contains information about butterflies (family, species and color)
  • Copy and paste the below contents into your text file
  • This will be the file you will use to populate your hash table

Swallowtail
Black Swallowtail
Black

Swallowtail
Western Tiger Swallowtail
Yellow

Swallowtail
Pipevine Swallowtail
Blue

Brush-footed Butterfly
Viceroy
Orange

Brush-footed Butterfly
Monarch
Orange

Brush-footed Butterfly
Julia Heliconian
Orange

Brush-footed Butterfly
Variegated Fritillary
Tan

Pieridae
Checkered White
White

Pieridae
Clouded Sulphur
Yellow

Pieridae
Cabbage White
White

Gossamer Wing
Gray Hairstreak
Gray

Gossamer Wing
Reakirt's Blue
Blue


ButterflyDatabase.java

  • Working with the butterfly.txt file provided above, write a user interface that works as shown in the sample output
  • This user interface must use a parallel BST and hash table into which you will insert the butterflies from butterfly.txt to pre-populate the database.
  • ButterflyDatabase.java must contain a main method that offers a list of options to the user.
  • Below is the starter code for this class:

/**
 * Butterfly Database class
 * @author
 * @author
 * CIS 22C, Lab 7
 */

import java.io.File;
import java.io.IOException;
import java.util.NoSuchElementException;
import java.util.Scanner;

public class ButterflyDatabase {
    public static void main(String[] args) throws IOException{
        HashTable<Butterfly> ht = new HashTable<>(24);
        BST<Butterfly> bst = new BST<>();
        Scanner input = new Scanner(new File("butterfly.txt"));
        input.close();
    }
}

  • Option A: Add a new Butterfly, prompts the user for family, species and color. Generates a species number. Inserts in the hash table AND the bst.
  • Option D: Display all Butterflies. Calls the inOrderPrint method of the BST class (not the print methods of the hash table - Why?).
  • Option R: Remove a Butterfly calls the remove method for both the hash table and BST to remove the Butterfly from both structures. If the Butterfly is not in the database, prints an error message as shown, and does not remove.
  • Option S: Search for a Butterfly calls the search method of the hash table (not the BST - Why?).
  • Option X: Prints "Goodbye" and ends the program. IMPORTANT: Does NOT print to a file (-10 point deduction)
  • After the user makes a selection, the menu should loop around again to allow the user to continue working with the hash table of books.
  • Additionally, you should add some error checking if the user enters an option other than A, D, R, S, or X.
  • Please see the example output below for more information.

Sample Output:

Welcome to the Butterfly Database!

Please select from one of the following options:

A. Add a Butterfly
D. Display all Butterflies
R. Remove a Butterfly
S. Search for a Butterfly
X. Exit

Enter your choice: H

Invalid Selection!

Please select from one of the following options:

A. Add a Butterfly
D. Display all Butterflies
R. Remove a Butterfly
S. Search for a Butterfly
X. Exit

Enter your choice: I

Invalid Selection!

Please select from one of the following options:

A. Add a Butterfly
D. Display all Butterflies
R. Remove a Butterfly
S. Search for a Butterfly
X. Exit

Enter your choice: A

Adding a butterfly!

Enter the family: pieRIDAE
Enter the species: Sleepy Orange
Enter the color: Orange

PIERIDAE: Sleepy Orange was added!

Please select from one of the following options:

A. Add a Butterfly
D. Display all Butterflies
R. Remove a Butterfly
S. Search for a Butterfly
X. Exit

Enter your choice: D

Species: Black Swallowtail
Family: SWALLOWTAIL
Color: Black
Species Number: 551

Species: Cabbage White
Family: PIERIDAE
Color: White
Species Number: 560

Species: Checkered White
Family: PIERIDAE
Color: White
Species Number: 558

Species: Clouded Sulphur
Family: PIERIDAE
Color: Yellow
Species Number: 559

Species: Gray Hairstreak
Family: GOSSAMER WING
Color: Gray
Species Number: 561

Species: Julia Heliconian
Family: BRUSH-FOOTED BUTTERFLY
Color: Orange
Species Number: 556

Species: Monarch
Family: BRUSH-FOOTED BUTTERFLY
Color: Orange
Species Number: 555

Species: Pipevine Swallowtail
Family: SWALLOWTAIL
Color: Blue
Species Number: 553

Species: Reakirt's Blue
Family: GOSSAMER WING
Color: Blue
Species Number: 562

Species: Sleepy Orange
Family: PIERIDAE
Color: Orange
Species Number: 563

Species: Variegated Fritillary
Family: BRUSH-FOOTED BUTTERFLY
Color: Tan
Species Number: 557

Species: Viceroy
Family: BRUSH-FOOTED BUTTERFLY
Color: Orange
Species Number: 554

Species: Western Tiger Swallowtail
Family: SWALLOWTAIL
Color: Yellow
Species Number: 552


Please select from one of the following options:

A. Add a Butterfly
D. Display all Butterflies
R. Remove a Butterfly
S. Search for a Butterfly
X. Exit

Enter your choice: R

Removing a butterfly!

Enter the family: gossamer WING
Enter the species: Summer Azure

Sorry! GOSSAMER WING: Summer Azure is not in the database.

Please select from one of the following options:

A. Add a Butterfly
D. Display all Butterflies
R. Remove a Butterfly
S. Search for a Butterfly
X. Exit

Enter your choice: R

Removing a butterfly!

Enter the family: brush-footed BUtterfly
Enter the species: Viceroy

BRUSH-FOOTED BUTTERFLY: Viceroy has been removed!

Please select from one of the following options:

A. Add a Butterfly
D. Display all Butterflies
R. Remove a Butterfly
S. Search for a Butterfly
X. Exit

Enter your choice: D

Species: Black Swallowtail
Family: SWALLOWTAIL
Color: Black
Species Number: 551

Species: Cabbage White
Family: PIERIDAE
Color: White
Species Number: 560

Species: Checkered White
Family: PIERIDAE
Color: White
Species Number: 558

Species: Clouded Sulphur
Family: PIERIDAE
Color: Yellow
Species Number: 559

Species: Gray Hairstreak
Family: GOSSAMER WING
Color: Gray
Species Number: 561

Species: Julia Heliconian
Family: BRUSH-FOOTED BUTTERFLY
Color: Orange
Species Number: 556

Species: Monarch
Family: BRUSH-FOOTED BUTTERFLY
Color: Orange
Species Number: 555

Species: Pipevine Swallowtail
Family: SWALLOWTAIL
Color: Blue
Species Number: 553

Species: Reakirt's Blue
Family: GOSSAMER WING
Color: Blue
Species Number: 562

Species: Sleepy Orange
Family: PIERIDAE
Color: Orange
Species Number: 563

Species: Variegated Fritillary
Family: BRUSH-FOOTED BUTTERFLY
Color: Tan
Species Number: 557

Species: Western Tiger Swallowtail
Family: SWALLOWTAIL
Color: Yellow
Species Number: 552


Please select from one of the following options:

A. Add a Butterfly
D. Display all Butterflies
R. Remove a Butterfly
S. Search for a Butterfly
X. Exit

Enter your choice: S

Searching for a butterfly!

Enter the family: brush-footed butterfly
Enter the species: Viceroy

Sorry! BRUSH-FOOTED BUTTERFLY: Viceroy is not in the database.

Please select from one of the following options:

A. Add a Butterfly
D. Display all Butterflies
R. Remove a Butterfly
S. Search for a Butterfly
X. Exit

Enter your choice: S

Searching for a butterfly!

Enter the family: GOSSAMER wing
Enter the species: Reakirt's Blue

GOSSAMER WING: Reakirt's Blue is in the database!

Please select from one of the following options:

A. Add a Butterfly
D. Display all Butterflies
R. Remove a Butterfly
S. Search for a Butterfly
X. Exit

Enter your choice: X

Goodbye!


What to Submit

  • Once you are certain your program is working as shown above, upload your files to Canvas under Lab 7.
  • You must submit the following files: Butterfly.java, BST.java, HashTable.java, HashTableTest.java, List.java, ButterflyDatabase.java, as well as the following JUnit Test Files (3 calls to assertEquals per test file):
    • CountBucketTest.java
    • GetNumElementsTest.java
    • SearchTest.java
    • InsertTest.java
    • RemoveTest.java
  • Please submit your files separately (-5 pts for zip or other compressed files)
  • Please remove all package statements before submitting (-5 pts).

How You Will Be Graded

  • You will receive 10 points for a correct Butterfly.java.
  • You will receive 70 points for a correct HashTable.java, along with a HashTableTest.java (7 points per correct method + 5 points per JUnit test file + 2 points for adding more method calls to HashTableTest.java other than what was provided in the starter code)
  • You will receive 20 points for a ButterflyDatabase.java that works identically to the example above (including formatting).
  • -10 points for writing to an output file at the end of ButterflyDatabase.java
  • -5 points for not removing package statements from the top of your file(s)
  • -5 points for not submitting pair programming contract (both parnters must submit)
  • -5 pts for zip or other compressed files
  • -5 points per file with an incorrect name