cs3101-003 Java
spring 2003
homework #4
due Wed Feb 19, by 6AM -- electronic submission

goal.
The goals of this assignment are to:

  1. learn how to use a Vector
  2. practice using Java keyboard I/O
  3. practice using Java file I/O

program.
In this assignment, you will write a program that will store weather conditions in a file. You will enter current weather conditions using the keyboard and your program will compute simple statistics on the conditions and record them in a file.

  1. Create a public class called Weather. A Weather object will record the weather conditions at a given time. It will store the following: You will need at least one constructor and a number of methods. Decide what you need and write the methods.

  2. Create another class that contains a main method and name this class hw4<yourname>. In this class, declare a global Vector variable that will contain multiple Weather objects. Also in this class, include the following methods: The main program should call readWeather(), outputWeather(), inputWeather(), weatherStats() and writeWeather() in that order.

  3. Include my Keyboard class, for handling the keyboard input. You may modify this code if you want to, but it is not required.

sample run.
Below is a sample run. The unix command line is highlighted in bold font.

unix$ java hw4sklar
enter name of weather data file: w.dat
Thu Feb 13 23:09:15 EST 2003 temperature=34 degrees, windchill=15 degrees, humidity=44%
Thu Feb 13 23:10:39 EST 2003 temperature=89 degrees, windchill=89 degrees, humidity=98%
please input the current weather...
conditions: cold
temperature: 3
windchill factor: 2
humidity: 1
average temperature = 42.0 degrees, average windchill = 35.333332 degrees, average humidity = 47.666668%
unix$ more w.dat
1045195755030 clear 34 15 44
1045195839539 cloudy 89 89 98
1045196213207 cold 3 2 1
unix$
Hint! Notice that inside the data file, the date of each observation is stored as a long -- the number of milliseconds since midnight GMT, Jan 1, 1970.

source code.
Your source code (i.e., your .java file) must be neat and clearly commented. You must have a header comment and you should comment the end of each block (i.e., each }).

submission.

  • Be sure to name the Java file with the main in it: hw4<yourCSusername>.java
    For example, mine would be called hw4sklar.java.
    BE SURE TO NAME YOUR FILE USING ALL lower case LETTERS!!!

  • Submit your program electronically.
    Follow the submission instructions for hw1, making sure you log into cluster.cs.columbia.edu to run the submit script.
    Make sure that you submit all three files: Also make sure that you use 4 as the argument to the submit script (instead of 4), since this is homework #4.

    points.
    This assignment is worth 15 points (out of 100 for the semester). Distribution of points is: