There is one programming question and a set of short answer questions.
Instructions for submitting your programming question solution are given in the Programming question section. You may submit as many times as you want; your most recent submission will be the one recorded.
Instructions for submitting your answers to the short answer questions are given in the Short Answer Questions section. You may submit as many times as you want; your most recent submission will be the one recorded.
Implement this API. A jar file containing some required resources can be found here. A skeleton can be found here. The skeleton does not compile, the constructors are not implemented and the methods do not return the correct values; you should complete the constructors and methods to satisfy their APIs. The provided code does not provide any fields; you must decide what fields are required by your implementation.
eecs2030.test4
package.
For reference: the Java API is here.
Submit your program using the following command in a terminal (make sure you are in the directory containing your file WeeklyForecast.java):
submit 2030 test4C WeeklyForecast.java
package eecs2030.test4; import java.util.ArrayList; import java.util.List; /** * A class that represents a weather forecast of exactly seven days. The first * day of the forecast is the weather for today. The forecast and its collection * of weather objects form a composition. * * @author EECS2030 Fall 2016-17 * */ public class WeeklyForecast extends Forecast { /** * The number of days in this forecast. */ public static final int DAYS = 7; private List<Weather> weather; /** * Initializes this weekly weather forecast using the provided list of * weather objects. The size of the list must be equal to * <code>WeeklyForecast.DAYS</code> otherwise an exception is thrown. * * @param weather * the list of weather objects for this forecast * @throws IllegalArgumentException * if the size of the list is not equal to WeeklyForecast.DAYS */ public WeeklyForecast(List<Weather> weather) { super(WeeklyForecast.DAYS); if (weather.size() != WeeklyForecast.DAYS) { throw new IllegalArgumentException(); } this.weather = new ArrayList<Weather>(weather); } /** * Initializes this weekly weather forecast by copying another forecast. * * @param other * the forecast to copy */ public WeeklyForecast(WeeklyForecast other) { this(other.weather); } /** * Returns a deep copy of the list of weather objects for this forecast. * * @return a deep copy of the list of weather objects for this forecast */ public List<Weather> getWeather() { List<Weather> result = new ArrayList<Weather>(); for (Weather w : this.weather) { result.add(new Weather(w)); } return result; } /** * Get the predicted weather for <code>n</code> days from today. * * @param n * the number of days from today * @return the predicted weather n days in the future * @throws IllegalArgumentException * if n is less than zero or greater than (WeeklyForecast.DAYS - * 1) */ @Override public Weather getWeather(int n) { if (n < 0 || n > 6) { throw new IllegalArgumentException(); } return new Weather(this.weather.get(n)); } /** * Returns a string representation of this weather forecast. The string * starts with "Seven day weather forecast:\n" and is followed by the string * returned by <code>Forecast.toString</code>. * * @return a string representation of this weather forecast */ @Override public String toString() { String s = "Seven day weather forecast:\n" + super.toString(); return s; } }
Enter your answers into a text file named answers.txt
.
You can use the editor of your choice for this. You can also create a
text file in Eclipse by selecting "New" and then "Untitled Text File" in
the "File" menu. Make sure that you save your file.
Also make sure that you indicate which question you are answering,
e.g. Q1: answer to question 1 Q2: answer to question 2 Q3:...
Submit your answers using the following command in a terminal (make sure you are in the directory containing your file answers.txt):
submit 2030 test4C answers.txt