Question: Adding DailySummary objects to a WeatherStation 1. Write a WeatherStation::add that adds a DailySummary object to the station. a. you may not add a null

Adding DailySummary objects to a WeatherStation 1. Write a WeatherStation::add that adds a DailySummary object to the station. a. you may not add a null DailySummary b. you may not add a DailySummary for the same date (month, day, and year) as an already-added DailySummary 2. Your WeatherStation::add method must handle the following test cases: a. any and all precondition checks b. adding a DailySummary with a date that is a duplicate of an already-added DailySummary c. adding a single DailySummary d. adding multiple DailySummary objects Find the hottest day recorded at the WeatherStation 1. Write a WeatherStation::findHottestDay that

import java.time.DateTimeException;

import java.time.LocalDate;

import java.util.ArrayList;

/**

* Summary of weather data for a particular day.

*

* @author CS1301

*

*/

public class DailySummary {

public static int FREEZING_POINT = 32;

private LocalDate date;

private ArrayList hourlyMeasurements;

/**

* Creates a new DailySummary, with no hourly measurements, for the given month,

* day, and year.

*

* @precondition month/day/year is a valid date

* @postcondition getYear()==year && getDay()==day && getMonth()==month &&

* getNumberOfMeasurements()==0

*

* @param month

* the month for this measurement

* @param day

* the day-of-the-month for this measurement

* @param year

* the year of this measurement

*/

public DailySummary(int month, int day, int year) {

try {

this.date = LocalDate.of(year, month, day);

} catch (DateTimeException e) {

throw new IllegalArgumentException("Invalid date.");

}

this.hourlyMeasurements = new ArrayList();

}

/**

* Gets the year associated with this daily summary

*

* @precondition none

* @postcondition none

*

* @return the year

*/

public int getYear() {

return this.date.getYear();

}

/**

* Gets the month (as a number between 1 and 12) associated with this daily

* summary

*

* @precondition none

* @postcondition none

*

* @return the month

*/

public int getMonth() {

return this.date.getMonthValue();

}

/**

* Gets the day-of-the-month associated with this daily summary

*

* @precondition none

* @postcondition none

*

* @return the day-of-the-month

*/

public int getDay() {

return this.date.getDayOfMonth();

}

/**

* Gets the number of measurements for the day.

*

* @precondition none

* @postcondition none

*

* @return the number of measurements for the day.

*/

public int getNumberOfMeasurements() {

return this.hourlyMeasurements.size();

}

/**

* Gets all the hourly measurements

*

* @precondition none

* @postcondition none

*

* @return the collection of hourly measurements

*/

public ArrayList getHourlyMeasurements() {

return this.hourlyMeasurements;

}

/**

* Adds an HourlyMeasurement to this summary.

*

* @precondition measurement != null && measurement.getHourOfDay() does not

* match the getHourOfDay() of an already-added measurement

* @postcondition getNumberOfMeasurements() = getNumberOfMeasurements()@prev + 1

*

* @param measurement

* the measurement to add

*

* @return true if added measurement, false otherwise.

*/

public boolean addHourlyMeasurement(HourlyMeasurement measurement) {

if (measurement == null) {

throw new IllegalArgumentException("measurement cannot be null.");

}

if (hasMeasurementFor(measurement.getHourOfDay())) {

throw new IllegalArgumentException("Cannot add measurement for hour that already exits.");

}

return this.hourlyMeasurements.add(measurement);

}

it is in java

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!