Assignment #11

Instructions

  1. The purpose of this assignment is to sort the data from your CSV file, using interface Comparable and the compareTo() method.
  2. Take your code from assignment #8, #9, or #10.
    1. Here is starter code: LastnameFirstname11.java
    2. Read over how interface Comparable works:
      1. Comparable.java is interface Comparable with a detailed description of how it is implemented.
      2. Java API Interface Comparable has even more details.
    3. Add interface java.lang.Comparable to the first line of your class HawaiianTheme. For example:
      class HawaiianTheme implements java.lang.Comparable{
    4. Add the compareTo() method to class HawaiianTheme to sort any data field that you wish. In other words, write a compareTo() method definition nested inside your class HawaiianTheme that sorts one of the data fields of class HawaiianTheme. Here are examples of compareTo() method definitions:
      1. Fraction.java shows an example compareTo() method.
      2. Name.java shows an example compareTo() method.
      3. ThreeNames.java shows an example compareTo() method.
    5. To prevent the automatic output of the Sorting.java program, use this code before you sort: Sorting.display = false;
    6. Use the one of the methods from the Sorting.java program to sort your array of HawaiianTheme objects. In other words, in your main() method, write a method call from one of the sorting methods from the Sorting.java program. For example:
      Sorting.selectionSort(arrayOfHawaiianThemeObjects);
      Here are examples of sorting method calls:
      1. TestComparable.java shows examples of using interface Comparable by comparing two objects of several different classes.
      2. Sorting.java shows examples of using interface Comparable for sorting arrays with different sorting algorithms.
  3. Make sure your code follows the ICS 211 Java Coding Standard, in particular the Java documentation (Javadoc) comments that go above each method.
  4. Write your original comments every 3-5 lines of code.
  5. WARNING: In the edit method, do NOT copy my code or my comments. Use my code as a guide to write your own code.

Example Output

You output will be similar, but not the same, as my output. The formatting doesn't have to be exactly the same, but make sure it is neat and easy to read. Here are details on the format() method, if you so wish to use it: https://docs.oracle.com/javase/7/docs/api/java/util/Formatter.html Or, in your CSV file, just make sure you leave extra spaces to evenly space the words. Or, maybe you have your own unique way to do the formatting!

** Make sure you submit your CSV file with your assignment. **

Below is example output for using this input file as the first commandline argument: mammals2.csv


Display MarineMammalsOfHawaii array[] without initializing elements:
index   element
  0     null
  1     null
  2     null
  3     null
  4     null
  5     null
  6     null
  7     null
  8     null
  9     null
  10     null
  11     null
  12     null
  13     null
  14     null
  15     null
  16     null
  17     null

Read from input file: mammals2.csv

Display MarineMammalsOfHawaii array[] after initializing elements:
index   name                        population   length (meters) Genus species
  0     Hawaiian monk seal               1100      2.40          Monachus schauinslandi
  1     humpback whale                  10000     16.00          Megaptera novaeangliae
  2     spinner dolphin                  3351      2.35          Stenella longirostris
  3     common bottlenose dolphin         235      3.50          Tursiops truncatus
  4     Risso's dolphin                 85000      4.00          Grampus griseus
  5     rough-toothed dolphin          150000      2.83          Steno bredanensis
  6     striped dolphin               2000000      2.60          Stenella coeruleoalba
  7     pygmy killer whale                817     20.50          Feresa attenuata
  8     false killer whale                150      2.80          Pseudorca crassidens
  9     melon-headed whale               2950      3.00          Peponocephala electra
 10     short-finned pilot whale         8850      3.70          Globicephala macrorhynchus
 11     sperm whale                      7082     17.30          Physeter macrocephalus
 12     dwarf sperm whale               19000      3.00          Kogia sima
 13     pygmy sperm whale                  50      3.50          Kogia breviceps
 14     orca                               50     10.70          Orcinus orca
 15     Blainville's beaked whale        2200      5.00          Mesoplodon densirostris
 16     Cuvier's beaked Whale           13000      8.30          Ziphius cavirostris
 17     pantropical spotted dolphin   3000000      2.50          Stenella attenuata

index   name                        population   length (feet)   Genus species
  0     Blainville's beaked whale        2200      5.00          Mesoplodon densirostris
  1     common bottlenose dolphin         235      3.50          Tursiops truncatus
  2     Cuvier's beaked Whale           13000      8.30          Ziphius cavirostris
  3     dwarf sperm whale               19000      3.00          Kogia sima
  4     false killer whale                150      2.80          Pseudorca crassidens
  5     Hawaiian monk seal               1100      2.40          Monachus schauinslandi
  6     humpback whale                  10000     16.00          Megaptera novaeangliae
  7     melon-headed whale               2950      3.00          Peponocephala electra
  8     orca                               50     10.70          Orcinus orca
  9     pantropical spotted dolphin   3000000      2.50          Stenella attenuata
 10     pygmy killer whale                817     20.50          Feresa attenuata
 11     pygmy sperm whale                  50      3.50          Kogia breviceps
 12     Risso's dolphin                 85000      4.00          Grampus griseus
 13     rough-toothed dolphin          150000      2.83          Steno bredanensis
 14     short-finned pilot whale         8850      3.70          Globicephala macrorhynchus
 15     sperm whale                      7082     17.30          Physeter macrocephalus
 16     spinner dolphin                  3351      2.35          Stenella longirostris
 17     striped dolphin               2000000      2.60          Stenella coeruleoalba