Question: Introduction to data structures. (Please help me with the UML diagrams also.) Thanks! Objective Implement and manipulate an ORDERED LIST collection class. Problem Description You




Objective Implement and manipulate an ORDERED LIST collection class. Problem Description You will be writing a program to manage an ordered list of "things" where you get to choose the things" in the list. Start by choosing what sort of list you would like to keep. For example: To-do list Vacation and travel information Real estate properties * pretty much any sort of list You can be creative about your list. However, it is prohibited to use books, points, lines, circles, grocery items, students. persons, bank accounts, menu items, cars, pets or songs. Please note that you may end up reusing your "Thing" class across more than one programming assignment, so choose something that interests you. Thing Class Your Thing class must have the following characteristics a meaningful name (not "Thing") at least 3 instance variables such that: o the first instance variable must be of type String and this variable will be used as a search key o the second instance variable must be integer (i.e., int) and this variable will be used to find aggregate information about Things that are stored in a collection class as will be explained later o the third variable must be of type boolean o All instance variables must be private Implement a three-arguments constructor for your Thing class. The arguments must be in the order (String, int, boolean). Implement getters and setters for all the attributes of your Thing. (Note that Eclipse will automagically create them for you with Source Generate Getters and Setters) Implement a toString method that returns a String representation of your Thing where all the instance variables are in one line and separated by tabs (Eclipse will automagically create a toString() method for you with Source | Generate toString(). However, the format will not be correct.) Implement the equals() method for your Thing where two Things are considered equal when they have the same search key. Note that the equality of String attributes should be case insensitive. For example, "MATH". "math" tobbath In and should be case insensitive. For example, "MATH", "math" and "Math" match each other. In order to compare strings in Java use the String's equalsignoreCase() method. For example, the following code should print true: String strl = "Hello"; String str2 = "hello"; System.out.println(stri.equalsIgnorecas e (str2)); (Again, Eclipse will automagically create an equals() method for you with Source Generate hashcode() and equals(). However, you may have to make changes to it to meet this program specification.) Implement the Comparable interface and the compare Too method for your Thing, compare To() returns . a negative number when the invoking object's search key is less than the parameter's search key . when the two search keys are equal . a positive number when the invoking object's search key is greater than the parameter's search key o For example, "ant".compare To("bat") will return a negative number. o Your compareTomethod must compare two Things. Note that the comparison of String attributes should be case insensitive. For example, "MATH", "math" and "Math" must match each other. Collection Class Implement a collection class of your things using an array. a. You may NOT use the Java library classes ArrayList or Vector or any other java collection class. b. You must use simple java Arrays in the same way as discussed in class. The name of your collection class should include the name of your Thing. For example, if your Thing is called Student, then your collection class should be called Student Collection. Implement a constructor for your collection class that takes one input parameter that represents the maximum number of elements that can be stored in your collection. Your collection class should implement the Your collection class should implement the DataCollection interface which has been provided in D2L with the programming assignment. The interface file is named DataCollection.java. Do not change the interface file in any way, but simply add it to your Eclipse project. . With the exception of an error message in insert(), no method in the collection class should print anything. Implement the following methods in your collection class, as defined in the DataCollection interface: 1. void insert (Thing): a method that takes one input parameter matching the type of your Thing and then inserts it in the collection class IN DESCENDING ORDER according to the search key instance variable. Write a try/catch block to handle any exception that might occur (such as attempting to insert into a full list). You may print a message from your catch block. Unlike program #1, simply add any duplicate Things. 2. int size(): a method that returns the number of objects in the collection. 3. String toString(): a method that returns a String representation of the collection that includes all elements that are stored in the collection. The output string must be nicely formatted in a tabular format, one Thing per line. toString() will not print but rather will return a String. For example, a String representing a list of students (in reverse order by name) could be formatted as follows: Name Age Registered Reem Mohammed Maria Hanna 27 25 20 30 true false true true 4. Thing find (String): this method depends on the search key attribute of your Thing class. The method takes as input a string value and returns the first object with a search key that matches the input search value. Use the compareTo () method from your Thing class. Note that you must convert the String parameter into a Thing object by calling the Thing constructor. 5. int countOccurrences (boolean): this method has a boolean parameter. Depending on the value of the parameter, the method returns the number of Things whose boolean instance variable is true or the number of Things whose boolean instance variable is false. 6. boolean contains (Thing): this method takes 6. boolean contains (Thing) : this method takes one input parameter matching the type of your Thing. The method returns true or false based on whether the collection contains at least one thing that is equal to the input parameter. Use the equals() method from your Thing class to determine if two objects are equal. 7. int total(): this method uses the int instance variable of your Thing class. The method calculates and returns the sum of the int instance variables of all objects stored in the collection. For example, in the student collection, this method finds the sum of age of all students in the list (102 in the example) 8. double average(): this method returns the average of the int instance variables of all objects stored in the collection 9. int countRange (int low, int high): this method depends on the int instance variable of your Thing class. The method takes as input two int values and counts how many objects in the list have a value that lies in the given range including the endpoints. For example, in the student collection class that is displayed above, countRange (25,30) returns 3 because there are 3 students with age values that fall in the range between 25 and 30 inclusive. Note that if the first input parameter is greater than the second input parameter then the method always returns 0 (i.e.. count Range (30,25) returns 0). 10. Write an iterator class for your collection that iterates through your collection and returns the items in the list in the order in which they are stored. The results will be similar to toString() except that the iterator returns one Thing at a time. Your iterator will have constructor, hasNext() and next() methods. Implement your iterator as an embedded class as shown in class. Add an iterator method to your collection class. Driver Class Implement a Driver class that includes a test program to: Create a collection class with capacity 10. Use the insert() method to insert 5-10 items in the collection. You may use any arbitrary values in the objects to be inserted. The driver tests all the methods of the collection class. Display the results of each operation after it is performed. Label your output clearly. Do not use a Scanner to read any inputs from the user. Instead, use hard coded values for the different methods inputs. Extra Credit 1. EXTRA CREDIT: Cause your iterator to display the list in alphabetical order (remember that your list is stored in reverse alphabetical order). Extra Credit 1. EXTRA CREDIT: Cause your iterator to display the list in alphabetical order (remember that your list is stored in reverse alphabetical order). 2. EXTRA CREDIT: void delete (Thing): this method takes one input parameter of your type of Thing, The method then searches the collection for the first object that equals the input object and deletes its occurrence if found. After the item has been deleted, the list must still be maintained IN ORDER Other Requirements Draw a UML structure diagram showing the relationship between the classes in your solution. You may hand draw or use any tool of your choice but the diagram must be submitted in a format that I can read (one of .doc, .docx, .pdf, .jpg, .txt). If I cannot read it, I cannot grade it. Draw a UML class diagram for your collection class (may be combined with the structure diagram). . Note that automated tools often do not follow the conventions that I require. Factor the classes as described above. This just means you should implement 4 classes (including the iterator) and put the methods in the correct class as indicated above. It also means that instance variables are private and one class should not interfere with the internal workings of another class. . Using Javadoc style, comment your collection class. In the comments, document the invariant for your collection class. Use good coding style throughout (see slide deck 01-D Objects and Chapter 1 of your text) including o correct private/public access modifiers o consistent indenting o meaningful variable names o normal capitalization conventions o other aspects of easy-to-read code You are free to adopt and adapt code from the textbook and class slides. However, document the source of any borrowed code
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
