/* CSC 17 Hashing Lab Be sure to download and study carefully my TDHash.java and student2.java. Part 1:--- In the following code you will find a class 'date' that represents a calendar date, such as 10/11/2017, which is created using new date(10,11,2017); The class implements compareTo and overrides the hashCode, toString and .equals methods of the Object superclass. Following that is a class called "event" that records an event, like a diary entry. Each event consists of a title (String), time (date object) and a description (String). Assume that each event can be uniquely identified by either the title or the date. Create a subclass of TDHash for a hashtable of events, with first key the title and second key the date. Study and follow the student2d.java example of how to create a concrete subclass of TDHash. The following main should work with your code, assuming that your concrete class name is 'eventhash' public static void main(String[] av) { eventhash EH = new eventhash(100,100); EH.insert(new event("halloween",new date(10,31,2017),"just tricks")); EH.insert(new event("thanksgiving",new date(11,25,2017),"eat turkey")); EH.insert(new event("new year",new date(1,1,2018),"party")); System.out.println(EH.search("halloween",new date(10,31,2017))); System.out.println(EH.search1("thanksgiving")); EH.delete1("thanksgiving"); System.out.println(EH.search1("thanksgiving")); System.out.println(EH.search2(new date(1,1,2018))); } Part 2:--- After a while, as events accumulate, you discover a problem: sometimes there are multiple events on the same day: EH.insert(new event("csc17 midterm",new date(10,31,2017),"prof gives test on Halloween!")); There are also multiple events with the same title: EH.insert(new event("new year",new date(1,1,2019),"party again")); A single key is no longer enough to uniquely identify a value stored in the hash table. Thus when you search using one of the keys, you must return a 'Collection' of events. delete1/delete2 should similarly be modified to delete all events sharing a common key. You can assume that it takes two keys to uniquely identify an object (so search(key1,key2) should still return a unique value). To implement this adjustment, you must copy and edit (not extend this time) my abstract TDHash class. Make a new class with few changes as possible. Be sure you understand: you're not just writing a hash table class for events, but an abstract hash table for abstract types . You must maintain the same level of abstraction, including using an abstract Collection structure (as opposed to ArrayList). After you're done, redo your concrete class for events with further tests (include the "csc17 midterm" event and the new date(1,1,2019) event). Hints: 1. Read the documentation for the java.util.Collection interface: you will discover useful functions such as addAll and removeAll. 2. At one point, you will be tempted to write a line that looks like this: Collection C = new Collection(); But this line won't compile because Collection is an interface, not a class. You will have to figure out how to work around this by making something 'abstract' (to be implemented in subclass). But remember, only as little as possible should be made abstract: do not make the entire search function abstract! hint to hint: if an interface or abstract class specifies that you must implement a Object f(); you can implement it with public Object f() { return "abc"; } This is valid because a string is an Object. In fact you can also implement it as public String f() { return "abc"; } and Java will still accept this as a valid implementation of the interface spec: this is called "covariant typing". ******** ADDITIONAL HINTS WILL BE PROVIDED IF YOU ASK! ********* */ import java.util.*; // date objects class date implements Comparable { protected int year; // negative years allowed, represents BC protected int month; protected int day; protected int[] DM = {31,28,31,30,31,30,31,31,30,31,30,31}; //days in month protected boolean leapyear() { return year%4==0; } // constructor public date(int m, int d, int y) { year = y; if (leapyear()) DM[1]=29; else DM[1]=28; if(m>0 && m<13 && d>0 && d<=DM[m-1]) { month=m; day = d; } else throw new RuntimeException("invalid date"); } // overriding inherited functions from class Object: public String toString() { return month+"/"+day+"/"+year; } public int hashCode() { return year*12*31+month*31+day; } public int compareTo(date B) { return hashCode() - B.hashCode(); } public boolean equals(Object B) // must be object to override Object.equals { date D = (date)B; return D.year==year && D.month==month && D.day==day; } }//date // sample: date halloween = new date(10,31,2017); // event objects class event { public final String title; public final date time; protected String description; public event(String t, date d, String s) { title=t; time=d; description=s; } public String toString() { return "Event: "+title+", Date: "+time+"\n"+"Description: "+description+"\n"; } } // sample; event e = new event("midterm",new date(10,31,2017),"students panic"); // event f = new event("thanksgiving",new date(11,25,2017),"eat turkey"); /// main for testing Part 2 public class diary { public static void main(String[] av) { ehash EH = new ehash(100,100); EH.insert(new event("csc17 midterm",new date(10,31,2017),"students panic")); EH.insert(new event("thanksgiving",new date(11,25,2017),"eat turkey")); EH.insert(new event("halloween",new date(10,31,2017),"just tricks")); Collection cv = EH.search1("thanksgiving"); for(event e:cv) System.out.println(e); cv = EH.search2(new date(10,31,2017)); for(event e:cv) System.out.println(e); }//main }