1
COM6471 – Foundations of object-oriented programming
Assignment 3 – Analysis of weather records (60%)
This is the second assignment for COM6471 Foundations of Object Oriented Programming, and it
is worth 60% of your final module mark. The deadline for submission is 15.00 on Friday 17
December.
The aim of this assignment is to test your ability to:
• Write an object oriented program in Java that makes use of several different classes.
• Write classes from a basic specification, which is vague in some details.
Ensure that you read the entire assignment specification carefully before you begin. This is a much
more challenging assignment than the first two, and you will need to allow some time to plan your
code before you begin writing it.
Introduction
This assignment requires you to build a Java program to analyse and display records of
temperature and wind speed recorded between 1999 and 2016 at a weather station on the top of
a Scottish mountain called Cairngorm; see https://www.geograph.org.uk/photo/3728168 for
some more information about this mountain and the weather station.
The weather data can be accessed from https://cairngormweather.eps.hw.ac.uk/archive.htm , and
can be downloaded as text, where each observation is separated by a comma. For example, data
recorded during 2002 can be found at https://cairngormweather.eps.hw.ac.uk/2002/data2002.txt,
where the meaning of each field at https://cairngormweather.eps.hw.ac.uk/new_aws_data.htm.
You should be aware that these are real-world data, and so there are some inconsistencies in
filenames and file structure from one year to the next. For some years the data are available in
more than one format (e.g. https://cairngormweather.eps.hw.ac.uk/2006/). In these cases, you
should retrieve data from the *.txt file, not *.csv or anything else. Furthermore, some data are
missing. Your code is expected to deal with these inconsistencies, so at an early stage you should
ensure that you are familiar with the data from each year.
Task overview and main requirements
The aim of this assignment is to write a Java program that allows a user to
• Select a year in the range 1996 to 2016 (e.g. 2002).
• Select a type of observation to be either temperature or wind speed.
• Select a start day and end day (both in the range 1-365) for analysis.
• Display the maximum, minimum, and mean values of that observation for the selected day
range in the terminal/command window.
• For extra marks, display a graph showing how that observation varied throughout the day
range in an EasyGraphics window.
Your code must include three classes, which should be called WeatherModel, WeatherView, and
WeatherController. The requirements for each of these classes are given below, with some
recommended ideas about methods that are intended to assist with the design of your program.
2
To help with reading data from the URL, you are provided with URLtest.java, which contains
some example code that reads data from a URL, and parses it into records separated by a comma.
You may use parts of this code in your assignment submission.
Required classes
Your program will conform to a Model-View-Controller design, which is a common pattern for
object-oriented programs (see https://www.oracle.com/technical-resources/articles/java/java-se-
app-design-with-mvc.html for some more detail). In this approach the model class is used to store
and represent data, as well as to control access to the data through a set of public methods. The
view class presents the data to the user, often via windows and a graphical user interface although
please note that a GUI is not required for this assignment. The controller class manages
interactions with the user, and translates requests into actions that the model class will perform.
The detailed requirements for each class are described below:
WeatherModel class
Your WeatherModel class must implement the following requirements:
• Create a data record (hint: this could be a separate class) that can store day, time,
windspeed (in miles per hour) and temperature (in degrees Celsius) data for an entire year.
• Read day, time, windspeed, and temperature for an entire year from a URL that is supplied
as an argument to a method. This requirement will involve opening a connection to the
URL, reading the data, parsing the data into separate fields, and then storing the data. The
code supplied in URLtest.java will help you with implementing this part of the program.
• The data read from the URL should be parsed as follows: day (range 1-365), column 2 (up
to 2006), column 1 (2007 onwards); time is recorded at 30 minute intervals in column 3 (up
to 2006) and column 2 otherwise; windspeed (mean over the 30 min period) is stored in
column 4 (up to 2006) and column 3 otherwise; temperature is stored in columns 9 and 10
(up to 2006) and columns 8 and 9 otherwise. There are two temperature sensors, and you
should return data from the first one (i.e. from column 9 (up to 2006) or column 8
otherwise).
• Return a list of temperature readings for the range of days that are provided.
• Return a list of mean wind speed readings for the range of days that are provided.
• If data for these days are not available or are unreliable (e.g. a mean wind speed of 0),
return a suitable message.
WeatherView class
Your WeatherView class should act as a viewer only, there is no requirement that this class should
act as a GUI. This class must however implement the following requirements:
• Calculate the mean, maximum, and minimum values of temperature or mean windspeed
over the selected range of days, and display these values in the command window or
terminal.
• Optionally (see below), plot a graph of temperature throughout the selected range of start
day to end day in an EasyGraphics window.
• Optionally, plot a graph of mean wind speed throughout the selected range of start day to
end day in a separate EasyGraphics window.
• Optionally highlight the maximum and minimum temperature and mean wind speed over
the selected range of days in each of the EasyGraphics windows.
3
WeatherController class
Your WeatherController class must implement the following requirements:
• It must include a main method, so that the program runs when java WeatherController
is typed on the command line.
• When the program runs, the WeatherController class must initiate dialog with the user
to select:
o a year in the range 1999-2016,
o a start day in the range 1-365, and
o an end day in the range 1-365.
• Construct a suitable URL and pass it to WeatherModel, so that data can be read and stored.
• Call methods in WeatherView to display the data on the command window or terminal,
and (optionally) in EasyGraphics windows.
General requirements and implementation notes
• Where there is no exact specification (e.g. for the user dialog, and the format of the
graphs), you are free to choose a suitable approach.
• Your code must compile from the command line, and should not be assigned to a package.
• You can use any of the classes provided in the Java API
(https://docs.oracle.com/en/java/javase/17/docs/api/index.html)
• You must not use any other third party Java API or code library except for the sheffield
package
• Your code must retrieve data from the Web pages, reading from a file is not sufficient.
Getting started
This assignment has a looser specification than assignments 1 and 2. Where the behaviour is not
clearly specified, then you are free to make your own design decisions.
As a first step you should write a test program to read data from a URL, and parse these data into
separate fields. Use and adapt the code provided in URLtest.java, so that you gain some
experience with the data available and how it is stored and accessed.
The next step is to consider what each of the classes in the program needs to know, and these will
become the class instance fields. The instance fields should be assigned values by the constructor
and should be accessible through public get methods. Consider any other methods that the classes
might need in order to deliver the required behaviour. It might be helpful to sketch out the
different classes on a piece of paper, noting down the instance fields and public methods that
each class needs.
Code each class incrementally and use a test harness – either a separate test class with a main
method, or a main method embedded in the class. For example, you could use a test class or
harness to check that WeatherController generates correct URLs, and a separate test class or
harness to check that WeatherModel reads the correct information when it is supplied with a URL.
Each time you make changes to the class, compile and test it. If it fails to compile, or runs
incorrectly, then go back over your most recent changes and isolate the problem.
Examine the weather data for each year carefully. Your code should take account of the possibility
that some of the data records might be missing or empty, and the filenames (and hence URLs) are
different for some years compared to others.
4
Submission and deliverables
Before you upload your code, check that it compiles on the on the command line using java. It is a
good idea to check that it compiles and runs on one of the University computers. Check that your
code is not part of a package. Do not submit archives (e.g. zip files) or .class files.
Your code should then be submitted as a java files and uploaded to Blackboard using the upload
tool before the deadline of 15.00 on Friday 17 December.
Assessment
Your code will be assessed for functionality, style, and flair. A mark of zero will be awarded for
programs that do not compile; it is therefore important that you check that your code compiles
before you submit it. Marks will be allocated as follows.
As before, half of the marks (30/60) will be awarded for functionality and half (30/60) for design,
testing, and style. There are many different ways to code the solution to this assignment. There is
no single “correct” solution. However, some solutions are better than others because they are
more concise, and more readable.
Functionality will be assessed as follows:
• Code compiles. If your code does not compile because it is incomplete then you will be
awarded a mark of zero.
• Data are retrieved from the website correctly for years in the desired range, taking account
of inconsistencies in filenames and data formats (10 marks).
• The correct mean, maximum, and minimum temperature and windspeed are displayed on
the command window/terminal (10 marks).
• Correct time series graphs for mean windspeed and temperature are displayed in windows
(10 marks, optional).
Design, testing and style will be assessed as follows:
• Design. Each class in the design has clear responsibilities and collaborations with other
classes, has an appropriate set of methods and instance fields, and suitable access
modifiers are used to preserve encapsulation (5 marks).
• Testing. Evidence of code used to test the behaviour of each class. This could be either a
test harness for each class, or a separate test class (5 marks).
• Style. Code is written with good style (15 marks). Code written in good style will have the
following characteristics:
• Each class will have a header comment, typically specifying the program name, the
author, and the date.
• The code is indented consistently throughout using four spaces and not tabs, so that
the code in each method is easily identified.
• Variables and methods have meaningful names (except for loop variables, which can be
a single letter, e.g. for (int j = 0; j <= max; j++) ). Variables and methods
should be in camelCase (e.g. weatherController).
• There are sufficient lines of code to meet the requirements, and no extra, unreachable,
or unnecessary code or comments.
• See https://software.ac.uk/resources/guides/writing-readable-source-code for further
details on how to write good quality readable code.
5
Unfair means
We take the use of unfair means very seriously1. This is an individual assignment. You must work
on it alone and hand in your own code. You must not share code with other students, or submit
work done by another student, or anyone else. All submissions will be run through specialised
software that detects similarity among Java programs, and action will be taken in cases where
unfair means are suspected.
November 2021
1 https://sites.google.com/sheffield.ac.uk/compgtstudenthandbook/menu/referencing-unfair-means
