// First implement this class class Friend { String name; String email; String favourite; public Friend(String Name, String Email, String Favourite) { name = Name; email = Email; favourite = Favourite; } public String toString() { return name + ", " + email + ", " + favourite; } } // Then implement this class class HashTable{ String[] keys; // Schluessel Friend[] data; // Daten final String empty = ""; // Freies Feld, only for deletion int count; // number of entries in the hash table HashTable(int initSize) { data = new Friend[initSize]; keys = new String[initSize]; count = 0; } // double size of hash table void Grow(){ Friend[] oldData = data; String[] oldKey = keys; // Allocate new arrays with twice the size data = new Friend[data.length*2]; keys = new String[keys.length*2]; // Insert keys & data from old hash table into new one, they have to be hashed again for (int i = 0; i= keys.length ) { Grow(); } } } // Get entry associated with key k public Friend Get(String k){ return data[Probe(k)]; } // Return if hash table contains k public boolean Has(String k){ return keys[Probe(k)] != null; } // return the current usage count public int Count(){ return count; } } class Main { static HashTable friends; static void ensure(boolean b) { if (!b) { throw new RuntimeException(); } } static void Set(String name, String tel, String adr) { friends.Set(name, new Friend(name, tel, adr)); ensure(friends.Get(name) != null); } static void Get(String k) { Friend e = friends.Get(k); if (e==null) System.out.println(k + ": null"); else System.out.println(e.toString()); } public static void main(String[] args) { friends = new HashTable(10); java.util.Scanner scanner = new java.util.Scanner(System.in); while (scanner.hasNext()){ String cmd = scanner.next(); // cmd "friend" for testing friend class in isolation if (cmd.equals("friend")){ Friend friend = new Friend(scanner.next(), scanner.next(), scanner.next()); System.out.println(friend.toString()); // cmd "set" for testing setting entry in hash table } else if (cmd.equals("set")) { Set(scanner.next(), scanner.next(), scanner.next()); // cmd "get" for testing getting entry in hash table } else if (cmd.equals("get")) { Get(scanner.next()); } else { System.out.println("Invalid input. terminating..."); break; } } scanner.close(); } }