Sorting out sorting assignment 3

  1. Create an ADT in Java that will represent a three-dimensional geometrical figure. Using the comparator pattern, implement java.lang.Comparable with the following rules specified by the user:
  1. Two figures are compared by their base area, by their height; or by their volume.

Note: The compareTo method will evaluate the different fields based on the comparison type.

  1. Write a testing program that will read a text file (entered at the command line) of random figures that adds them to an array or Vector/ArrayList. All figures must be manipulated as elements of the corresponding array or vector. The first value in the data file contains the number of figures in that file. A figure in the file is represented as follows (all values are separated by spaces):
    1. One of: Cylinder, Cone, Prism, Pyramid
    2. Cylinders and cones are followed by a double value representing the height and another double value representing radius.

e.g. Cylinder 9431.453 4450.123 or Cone 674.2435 652.1534

  1. Prisms are specified by the type of base polygon (SquarePrism, TrianglarPrism, PentagonalPrism, OctagonalPrism), a double (height) and another double (edge length).

e.g. SquarePrism 8945.234 3745.334

  1. Pyramids are followed by a double (height) and a double for edge length.

e.g. Pyramid 6247.53 2923.456

The testing application will then invoke the utility methods to re-arrange the figures according to the compare type from the largest to smallest. Assume the sorted algorithm is implemented. The compare type will be provided as input to your program. -h for height, -v for volume, and -a for base area. The program should print the time it took to sort the array for each sorting algorithm. It should also print the first and last value and every thousandth value in between. Implement the sorting algorithms as part of a utility class. It must sort an array or vector of Comparables. Make sure it is not dependent on the testing application and that it can be re-used in the future.

File name F, the compare type and the sort type are provided as parameters (-f –t –s or -F –T –S ) via command line. The program must be order and case insensitive. For example, all examples below are valid inputs:

java -jar sort.jar –fpolygons1.dat –Tv –Sb

java -jar sort.jar –ta –sQ –fpolygons4.dat

java -jar sort.jar –tH –Fpolygons2.dat –sB

where v is volume, h is height, a is base area, b is bubble, s is selection, i is insertion, m is merge, q is quick, and your implemented sort is z.