Description
Before Starting the Project
· Read sections 8.1 – 8.5 about ArrayLists
· Read this entire project description before starting
Learning Objectives
After completing this project, you should be able to:
· use ArrayLists to maintain and process collections of objects
· use for-each loops
· read data from external text files
Yellowstone National Park Geysers
Yellowstone National Park is home to the most geysers in the world. Hundreds of geysers erupt on a regular basis with Old Faithful being the most famous. Thousands of tourists gather during the summer months to watch it erupt about every ninety minutes. Park rangers have recorded geyser names, eruption times and dates for over one hundred years. You will create a database of information recorded in 2010. We simplified and cleaned up the data but there are still over 12,000 entries!
Step 1: Create a New BlueJ Project
Step 2: Download Data File
· Download the “GeyserData.txt” file and save it in the folder that BlueJ created for this new project. There are over 12,000 entries! You will not see the file within BlueJ but you can see it from within the Windows Explorer.
Step 3: Create a class called Eruption (5 pts)
This simple class stores information about a single geyser eruption: month, day and year of the eruption (integers), hour and minute of the eruption (24 hour clock) and the geyser name.
· Provide appropriate names and data types for each of the six instance variables.
· public Eruption (String info) – a constructor that initializes all of the instance variables to appropriate values given a single String. Read the background information about parsing Strings provided later in this document.
· provide get methods for each of the six instance variables.
· provide matching set methods for each instance variable. Although set methods are not used for this project it is good practice to provide them for most classes.
· public String toString( ) – return a formatted String. For example,
Great Fountain on 6/23/2010 at 23:59
· public static void main(String [] args) – thoroughly test each of the methods in this class.
Step 4: Create a class called Geyser (5 pts)
This simple class allows a different perspective of the eruption list. It stores information about an individual geyser and its total number of eruptions.
· Provide appropriate names and data types for the geyser name and number of eruptions.
· public Geyser (String name) – a constructor that initializes the geyser name.
· public void increment () – add one to the number of eruptions.
· public String getName () – return geyser name.
· public int getNumEruptions () – return number of eruptions.
· public static void main(String [] args) – thoroughly test each of the methods in this class.
Step 5: Create a class called GeyserDatabase (40 pts)
Create a class that maintains an unlimited number of geyser eruptions. Use the elegant for-each loop to search the ArrayList.
Class Fields
· Define an instance variable that holds an ArrayList of Eruption. Information is read from a text file.
· Define an instance variable that holds an ArrayList of Geyser. Information is created after reading the eruption data.
Constructor
A constructor is a special method with the same name as the class and generally initializes the fields to appropriate starting values. Refer to section 3.7.
· public GeyserDatabase ( ) – instantiate empty ArrayLists for eruptions and for geysers. No items are inserted yet. This method will be two lines of code.
Mutator Methods
A mutator method performs tasks that may modify class fields. Methods which simply set a field with the parameter value often begin with the prefix ‘set’. Refer to section 3.6.
· public void readGeyserData(String filename) – open the provided filename and read all the data. There are several thousand entries in “GeyserInfo.txt”. A sample solution is provided in the background section later in this document. Also, you will eventually invoke the helper method createGeyserList() but it will not be written until later.
· public void addEruption (Eruption e) – add the eruption to the ArrayList. This method contains one line of code.
Accessor Methods
An accessor method does not modify class fields. The names for these methods, which simply return the current value of a field, often begin with the prefix ‘get’. Refer to section 3.6.
· public ArrayList







