Assignment #17

Instructions

  1. The purpose of this assignment is to practice writing a class, creating objects of this class, and storing objects in a linked list.
  2. Download these four (4) files to your desktop:
    LinkedList.java
    ListInterface.java
    ListException.java
    Node.java
  3. Write a Java application that reads from an input file, which contains your data from Assignment #8 in CSV (Comma Separated Values) format, stores the data in a linked list, and outputs the linked list to the screen. We are re-doing Assignment #8, but using a linked list instead!
    1. The 1st step is to make your CSV file. Open up jGRASP. Cick: File, New, Plain Text, to create a new text file. Then, save the file as a CSV file by adding the .csv file extension when you save it: filename.csv Otherwise, open up a CSV excel file and type in your data. The 1st row should be the column names, separated by commas. The 2nd row, 3rd row, etc. should be the data from Assignment #2. Add a little more data, so you have at least 10 rows of data. Here is an example CSV file from the grocery list program: groceries.csv. And here is an exaple CSV file from my "Marine Mammals of Hawai'i" example: mammals.csv

      ** Make sure you submit your CSV file with your assignment. **
    2. The 2nd step is to write your program! Here is starter code: LastnameFirstname17.java You will have two classes - your public class LastnameFirstname17 and class HawaiianTheme.

      ** The class HawaiianTheme does NOT have the public modifier. **

      ** The class HawaiianTheme is NOT nested inside public class LastnameFirstname17. **

      ** The class HawaiianTheme is a class definition, which contains the variables (data fields) and methods to define objects, which store data. **

    3. class HawaiianTheme is the type of data that you stored in your input file. For example, I am using "Marine Mammals of Hawai'i", so my class is: class MarineMammalsOfHawaii
    4. The 1st commandline argument (args[0]) is the name of your input file that you just created. Have some error checking to make sure there is only one command argument.
    5. In your main() method, make a linked list to store objects of class class HawaiianTheme. See example file LinkedListDriver.java for examples of declaring a linked list of objects.
    6. The next step is to initialize the array with the data from the file. Earlier this semester, we read a file and stored it in an array with this program: ArrayBasedGroceryList.java. For this assignment, we do not use arrays. We are using a linked list.
    7. For each row in the CSV file, create a HawaiianTheme object.
    8. Then, use the add() method to add each HawaiianTheme object to the linked list. See example files LinkedListDriver.java and GroceryMenu.java for examples of adding objects to a linked list.
    9. After adding all the data from the CSV file to the linked list, display the linked list by using the toString() method.
    10. Ask the user what row they want to be removed from the linked list. Include some error checking for integer out of range and non-integer input.
    11. Use the get() method to display the object about to be removed from the linked list.
    12. Use the remove() method to remove the object from the linked list.
    13. Use the toString() method to re-display the linked list.
    14. Before we store data in our linked list, we have to create data fields, a constructor, and toString() method for class HawaiianTheme. This was done in Assignment #8. Also see instructions below.
    15. Below your public class LastnameFirstname08 class, create data fields, a constructor, and toString() method for class HawaiianTheme.
    16. Create three data fields - one data field for each of the attributes, which is the same as the three column names, in your class HawaiianTheme. For example, for my class MarineMammalsOfHawaii, I have these data fields: name, population, and length.
    17. Write the constructor for your class HawaiianTheme. You should have a three parameters, which initialize your three data fields. For example, I have three parameters of type String, Integer, and Double in my constructor.
    18. Write the toString() method for your class HawaiianTheme. The return value should return a String with the three data fields, so they can be displayed.
    19. See SimpleClass.java for an example of a class, constructor, toString() method, and an array of objects.
  4. Make sure your code follows the ICS 211 Java Coding Standard, in particular the Java documentation (Javadoc) comments that go above each method.
  5. Write your original comments every 3-5 lines of code.
  6. 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: mammals.csv

Read from input file: mammals.csv

Display MarineMammalsOfHawaii linked list
after adding objects from the input file into a linked list:
#  name                        population   length
1, Hawaiian monk seal               1100      2.40
2, humpback whale                  10000     16.00
3, spinner dolphin                  3351      2.35
4, common bottlenose dolphin         235      3.50
5, Risso's dolphin                 85000      4.00
6, rough-toothed dolphin          150000      2.83
7, striped dolphin               2000000      2.60
8, pygmy killer whale                817     20.50
9, false killer whale                150      2.80
10, melon-headed whale               2950      3.00
11, short-finned pilot whale         8850      3.70
12, sperm whale                      7082     17.30
13, dwarf sperm whale               19000      3.00
14, pygmy sperm whale                  50      3.50
15, orca                               50     10.70
16, Blainville's beaked whale        2200      5.00
17, Cuvier's beaked Whale           13000      8.30
18, pantropical spotted dolphin   3000000      2.50

Enter the row number of the object to be deleted: 0
ERROR: 0 is NOT a row number!
Enter the row number of the object to be deleted: 19
ERROR: 19 is NOT a row number!
Enter the row number of the object to be deleted: -99
ERROR: -99 is NOT a row number!
Enter the row number of the object to be deleted: 99
ERROR: 99 is NOT a row number!
Enter the row number of the object to be deleted: five
ERROR: five is NOT a whole number!
Enter the row number of the object to be deleted: 5

Deleting: Risso's dolphin                 85000      4.00

Display MarineMammalsOfHawaii linked list
after deleting an object from the linked list:
#  name                        population   length
1, Hawaiian monk seal               1100      2.40
2, humpback whale                  10000     16.00
3, spinner dolphin                  3351      2.35
4, common bottlenose dolphin         235      3.50
5, rough-toothed dolphin          150000      2.83
6, striped dolphin               2000000      2.60
7, pygmy killer whale                817     20.50
8, false killer whale                150      2.80
9, melon-headed whale               2950      3.00
10, short-finned pilot whale         8850      3.70
11, sperm whale                      7082     17.30
12, dwarf sperm whale               19000      3.00
13, pygmy sperm whale                  50      3.50
14, orca                               50     10.70
15, Blainville's beaked whale        2200      5.00
16, Cuvier's beaked Whale           13000      8.30
17, pantropical spotted dolphin   3000000      2.50