/* ******************************************************* * List method exercises: * ******************************************************* * In this section we will work on several methods for * the weather event and weather event list classes. * * The first step is to copy your class design and write * data examples and method templates for each class. * * Of course you knew that, but here are all six steps * for methods in case you forgot: * 1) Problem analysis and data design. * 2) Purpose statement and method header. * 3) Write examples. * 4) Copy your template. * 5) Fill in the template (write the function). * 6) Run your tests. * *******************************************************/ /* ******************************************************* * Equality methods: * ******************************************************* * First write a weather event comparison method. * It should compare the fields of this weather event * to the fields of its input, also a weather event. * ******************************************************* * Next, write methods to compare weather event lists. * An example for a different union hierarchy is given in * the file lab4-compare.java (linked off the lab page). * * The first method required for comparison is the general * union comparison (see samePicture in the example). * Each implementation compares the input to this object * using a helper method named after the current variant * (the specific class name of this instance). * * The other methods are the variant-specific comparisons. * See sameCircle, sameRectangle, and sameText in the * example code. These methods return false when the * two variant types don't match. This implementation * can be written once in the abstract class rather than * returning false separately in each mismatched variant. * When the variants match (comparing circles to circles, * text to text, etc.), the fields are compared directly * to determine equality. * * Implement these methods for the weather event list. * This is a lot of methods at once, so work through it * carefully. * If you have questions, consult with your partner. * If it is still unclear, ask a tutor or TA. * *******************************************************/ /* ******************************************************* * Insertion sort: * ******************************************************* * Comparison methods are useful, but two lists can * contain the same objects in different orders. Sorting * lists before comparison reveals whether they contain * the same objects regardless of order. * * A simple way of sorting lists is insertion sort. * A list is sorted recursively by inserting each element * at the correct position in the result of sorting the * rest of the list. * * Implement methods to sort weather event lists in * increasing order of temperature (so the coldest days * come first). Each variant will require a sort method * and an insert method. * *******************************************************/ /* ******************************************************* * Filter: * ******************************************************* * Sometimes we want to process (or compare) only part of * a list. In this case we wish to process the very * rainy (or snowy) weather events. Write a method * moreRainOrSnowThan for weather event lists. When given * a number of inches of precipitation, it should produce * a new list containing all weather events in this list * which represent more inches of precipitation. * *******************************************************/