CS 206: Data Structures
Exercise#13

Due on Tuesday, April 1

 

In Exercise 12, you created an application that reads a given file containing weather data and defined a class called, DailyWeather whose objects hold data for a single day. Look closely at your definition of DailyWeather. Did you define its data members as show below?

public class DailyWeather {

   private int month;

   private int day;

   private int year;

   private int high;

   private int low;

   private int/float precip;

   private int/float snowfall;



   ...

} // DailyWeather

If you did, you ignored the first tenet of data abstraction...abstract conceptually alike data into a sigle abstraction. In the above example, the date (month, day, year) is a conceptual entity that is very different from the rest of the data. You should define a separate class (say Date) for this purpose and then use composition to define the DailyWeather class. Keep all methods and operations relating to the Date class separate from the operations need on the weather data.

In the next version of your program you will do the following:

  1. From the handout given in class, learn to use the FileDialog class and include its use in your program.
  2. Modify your program to have a separate Date class that is then used in the DailyWeather class.
  3. Add to your application the following GUI elements/sections:
    - Allow user to enter any date, and then press a "Show Weather" button to retrieve the statistics for that day.

    - Allow user to enter any date (month and day only), and then press a "Show Statistics" button to retrieve the statistics for that day. These will include: The record high and low temps, the average high and low temp for that day and the average precipitation and snowfall amounts for that day.

    - Allow the user to enter a month and then press a "Get Monthly Data" button to retrieve weather statistics for the given month. The statistics should include: The average high and low temp for the month, the range of high and low temps in that month, and the average rainfall and snow in that month.

In order to accomplish this, you will need to store all the data in a list. This time use the LinkedList class from the java.util package. The interface is the same as the one you implemented.

Hand in a printout of your complete program along with the output for the following:

  1. Statistics for July 4, 1876 and July 4, 1976
  2. Statistics for the day you were born
  3. Monthly statistics for the month of March and April
  4. Statistics for April 1 (and perhaps the rest of the week).

Notes:

Implement the features one at a time, testing for each implemented feature each time. Java does have a built-in Date (and Calendar) classes, but we will not use them here. Use your own. In doing the computations, remember that in certain cases, the data is not available (or is insignificant). Your program your account for these (i.e. ignore them and not inlcude them in computing avarages). Your prigram will be graded based on correctness.

Start early. There are many individual components to this program. While each one of them is fairly easy, it is not advised that you try and finish it all in a single session.

 

 

 

Back to CS206 Course Materials