You will practice using inheritance and inner classes with two classes.
There are two parts of this homework. First, you must implement a class StringSorter that has the following methods:
void sortCaseInsensitive(List<String> list)
This method should sort the provided list using Collections.sort() and a custom Comparator object specified as an anonymous inner class. You may use the String.CASE_INSENSITIVE_ORDERComparator for this method.
sortByLength(List<String> list)
This method should sort the provided list using Collections.sort() and a custom Comparator object specified as an anonymous inner class. The Comparator object should sort by the length of the String objects. You may use Integer.compare() for this method.
sortByLastLetter(List<String> list)
This method should sort the provided list using the Collections.sort() and custom Comparator object specified as an anonymous inner class. The Comparator object should sort by the last letter in each String object. You may use the String.CASE_INSENSITIVE_ORDER Comparator and String.substring() for this method.
To receive full points for this part of the homework, you must (a) pass all of the unit tests provided in StringSortTester.java below and (b) use anonymous inner classes for each of the custom Comparator objects.
For the second part, you must extend the provided Polygon class to create a Triangle class that takes a base and height. When implementing the required methods from Polygon, the Triangle class should:
Calculate area as 0.5 × base × height.
Compare triangles by their area.
Always return "Triangle" as the name and 3 as the number of sides.
In addition to the methods Triangle must provide when extending the Polygon class, it should have:
Triangle(double base, double height)
A constructor that sets the base and height for the Triangle object. If negative values are provided, the constructor should default the base and height values to 0.
double getBase()
A method that returns the base value for the Triangle object.
double getHeight()
A method that returns the height value for the Triangle object.
To receive full points for this part of the homework, you must (a) pass all of the unit tests provided in TriangleTester.java below and (b) properly inherit the Polygon class.
You must submit this homework to your SVN repository using Eclipse. Your homework, including the src directory and all required source code files must be at the following location:
https://www.cs.usfca.edu/svn/<username>/cs212/homework04/
Replace <username> with your CS username in all lowercase letters.
The explicit locations required for key files are:
https://www.cs.usfca.edu/svn/<username>/cs212/homework04/src/Polygon.java
https://www.cs.usfca.edu/svn/<username>/cs212/homework04/src/Triangle.java
https://www.cs.usfca.edu/svn/<username>/cs212/homework04/src/TriangleTester.java
https://www.cs.usfca.edu/svn/<username>/cs212/homework04/src/StringSorter.java
https://www.cs.usfca.edu/svn/<username>/cs212/homework04/src/StringSorterTester.java
Your code must be committed by 11:59pm on Friday, February 22, 2013. Late homework is not accepted.