Assignment 5: Files
Introduction to Computer Program Design: Assignment 5
Due 17 Nov 7pm This is a Pass/Fail (P/F) AssignmentGoals
This assignment will give you practice at writing programs that read data from a file and do something with the dataResources and links
- Online Part: Online questions
- Programming part:
- Download Zip file
- Submit your java file.
- Marks and Feedback.
- Java Documentation
Online part
Start with the online part as it will help you consolidate your knowledge for the programming part. This part is compulsory and you must pass all the online questions related to this assignment by the deadline to pass this assignment.The Challenge questions are optional but would help your learning. Go to the Online questions now and answer all the Assignment 5 questions. There is no 24 hours grace period for these questions.
Programming part
To Submit:
-
WeatherReporter.java
setupGui
and main
methods.
When you have submitted this file, check that you can read the files listed on the submission page, and complete the submission process.
Zip file
WeatherReporter: Pass level
You must complete this part even if you want to do the Challenge level.Description
You are to complete theWeatherReporter
program to produce a graphical
visualisation of some New Zealand weather data stored in files.
The weather data (extracted from online MetOffice weather data from
24-26 January 2021) consists of measurements from weather stations
around NZ at every three hours over the three day period. Each weather
station reports measurements of temperature, dew-point, surface pressure, and
sea-level pressure.
The format of the data files consists of a series of "snapshots" of the
data over the country. Each snapshot has - a header line with the date and time of the snapshot (four integers for day, month, year, and time)
- a second header line with the number of weather-stations with reported measurements in the snapshot (which varies with the snapshot)
- a line of data for each weather station. Each line has 7 values:
- station name: one token, eg "Cape-Reinga"
- (x, y) coordinates on the map: two numbers, eg 186 38
- four numbers for temperature, dew-point, surface-pressure, and sea-level-pressure
Instructions and Tips:
You are to complete 2 methods:-
plotTemperatures()
should plot the temperatures for the first snapshot in a file. It should:- Ask for the name of the weather data file and open a Scanner on the file
- Call plotSnapshot, passing the Scanner as an argument, to plot one snapshot from the file.
-
plotSnapshot(...)
should:- Draw the map (in the file "map-new-zealand.gif")
- Read the date and time from the first header line and draw the date/time at the top-left of the map.
- Read the number of stations from the second header line, then
- For each station,
- Read the name, coordinates, and data, and
- Plot the temperature for that station at the coordinates
- Extend
plotShapshot(...)
so that it also identifies the highest and lowest temperatures from the weather stations in the snapshot and plots those temperatures with a larger circle (double the size of the other temperatures).
getTemperatureColor(...)
method useful to
work out the right color for a given temperature.
You should use the constants LEFT_TEXT
, TOP_TEXT
, for drawing the date/time and the constant DIAM
for drawing the circles.
WeatherReporter: Challenge level
Make sure you add all the appropriate UI components in order for the markers to test your contribution to the Challenge part. Complete theanimateTemperatures()
method so that it displays an animated
view of all the snapshots in a file, displaying each snapshot in turn, pausing briefly
(half a second) between each snapshot.
If you reuse plotSnapshot(...)
, then animateTemperatures()
should be very simple.
Since there is only one data file with multiple snapshots, your method can
read from weather-all.txt
without asking the user for the name of the file.
Implement at least two out of these four suggestions: - Write a
reportStation()
method to print a table of all the weather data from a single station, one line for each snapshot in the file.- The table should have a header.
- The table should be formatted to align all the data nicely.
- Then for each line of data for that station in the
weather-all.txt
file, it prints a line in the table with the date/time, temperature, dew-point, surface-pressure, and sea-level-pressure - If there are no entries for that station, it will print a message saying "Station not found".
- The animateTemperatures displays the date/time for each snapshot but doesn't show how far through the animation it has gone. Extend the program to show a slider bar that advances with each snapshot.
- Extend the plotting methods to allow the user to select what measure to plot (temperature, dew-point, surface-pressure or sea-level-pressure).
- Extend the plotting methods to allow the user to display all four measurements for each station (temperature, dew-point, surface-pressure or sea-level-pressure). You will need to work out a nice way of showing four values in a compact icon.