import java.util.*;

/*
    CS1102 Lab 9

    This is an ungraded lab.  You have one week to complete this lab.

    TITLE: A Phone Book for Monster.

    The Monster family wants to keep a database of all Monsters and their 
    handphone number.

    You are employed by the Monster Family to implement this phonebook for 
    them.  You are to maintain a list of Monster names and phone numbers 
    using a hash table, using Monster names as the keys. 
    
    COLLISION RESOLUTION
    
    For simplicity, you should resolve collision by linear probing (although 
    this is not a very good method).  
    
    REHASHING 
    
    You should also rehash your table by building a larger table when the 
    table is full.  Use the given list of prime number stored as array 
    sizeList in PhoneBook.  First, build a table with size sizeList[0].
    When the table is full, increase the table size to sizeList[1], and 
    so on.  You may assume that you never meed to maintain 
    more than 400 monsters.

    HASH FUNCTION

    To hash a Monster name, we use the hashCode() method provided by Java 
    class String.  hashCode() converts a String object to an int. We then 
    hash the values returned by hashCode() to map it to one of the slot in 
    our hash table.  The hash() function is already written to you in class
    PhoneBook.

    CLASSES PROVIDED

    We provide you with three classes: Monster is the usual data object.
    PhoneBookEntry is an entry in the phone book database.  PhoneBook 
    represents the phone book itself.  You are free to add additional
    methods and members in PhoneBookEntry and PhoneBook.

    YOUR TASK

    In this lab, you're required to write 4 methods for class PhoneBook:-
    add(), delete(), update() and find().

    (1) add(Monster m, int p) -- adds a monster m with phone number p to the
    phone book.

    (2) delete(Monster m) -- deletes monster m and its associated phone number 
    from the phone book.  Throws NoSuchElementException if monster m is not 
    in the phone book.

    (3) updates(Monster m, int p) -- changes the phone number of monster m to 
    p.  Throws NoSuchElementException if monster m is not in the phone book.

    (4) find(Monster m) -- returns the phone number of monster m.  Throws 
    NoSuchElementException if monster m is not in the phone book.

    You should plan carefully about how to write all 4 methods before you
    begin coding.
*/

class PhoneBookEntry {
  Monster monster;
  int phoneNumber;

  // ADD YOU OWN MEMBERS AND METHODS HERE
}

class PhoneBook {
  private static int sizeList[] = {5, 13, 37, 83, 173, 401};
  private PhoneBookEntry phoneList[];
  private int size;
  private int currSizeIndex;

  /**
   * Constructor for phonebook.  Allocate a phone book of size 
   * sizeList[0].
   */ 
  public PhoneBook()
  {
    currSizeIndex = 0;
  	phoneList = new PhoneBookEntry[sizeList[0]];
    size = sizeList[0];

  }

  public void add(Monster m, int p)
  {
    // ADD YOUR CODE HERE.
  }
  
  public int find(Monster m)
  {
    // ADD YOUR CODE HERE
    return 0;
  }

  public void update(Monster m, int p)
  {
    // ADD YOUR CODE HERE.
  }

  public void delete(Monster m)
  {
    // ADD YOUR CODE HERE.
  }  

  // YOU MAY ADD ANY PRIVATE METHODS YOU THINK IS NECESSARY.
}

public class MonsterPhoneBook {
  public static void main(String[] args) {

	PhoneBook phoneBook = new PhoneBook();

    Monster sulley = new Monster("James P. Sullivan");
    Monster mike = new Monster("Mike Wazowski");
    Monster boggs = new Monster("Randall Boggs");
    Monster henry = new Monster("Henry Waternoose");
    Monster celia = new Monster("Celia Mae");
    Monster dotcom = new Monster(".com");
    Monster cookie = new Monster("Cookie");
    Monster godzilla = new Monster("Godzilla");

	phoneBook.add(sulley, 2568691);
	phoneBook.add(mike, 2668311);
	phoneBook.add(boggs, 3042728);
	phoneBook.add(henry, 7774385);
	phoneBook.add(celia, 2559697);
	phoneBook.add(dotcom, 6917428);
	phoneBook.add(cookie, 6752378);
	phoneBook.add(godzilla, 2255288);

    System.out.println("***** finding some values *****");
    System.out.println(phoneBook.find(sulley)+" : "+sulley);
    System.out.println(phoneBook.find(dotcom)+" : "+dotcom);
    System.out.println(phoneBook.find(cookie)+" : "+cookie);
    System.out.println();

    System.out.println("***** updating some values *****");
    phoneBook.update(mike, 9779001);
    phoneBook.update(boggs, 3933011);
    phoneBook.update(godzilla, 7924614);
    System.out.println("***** after updating some values *****");

    System.out.println("***** deleting some values *****");
    phoneBook.delete(sulley);
    phoneBook.delete(cookie);
    phoneBook.delete(celia);
    System.out.println("***** after deleting some values *****");

    System.out.println("***** finding some values *****");
    System.out.println(phoneBook.find(henry)+" : "+henry);
    System.out.println(phoneBook.find(boggs)+" : "+boggs);
    System.out.println(phoneBook.find(godzilla)+" : "+godzilla);
  }
}


