#23 added constructor in Task class, implemented SevereWeather, WeatherService, WeatherGradenTaskPlanner

This commit is contained in:
Gian-Andrea Hutter 2022-11-22 14:44:56 +01:00
parent f7105f041c
commit 670938ef85
4 changed files with 91 additions and 0 deletions

View File

@ -0,0 +1,5 @@
package ch.zhaw.gartenverwaltung.io;
public enum SevereWeather {
FROST,SNOW,HAIL,NO_SEVERE_WEATHER
}

View File

@ -0,0 +1,64 @@
package ch.zhaw.gartenverwaltung.io;
import ch.zhaw.gartenverwaltung.types.Crop;
import ch.zhaw.gartenverwaltung.types.Task;
import java.io.IOException;
import java.time.LocalDate;
import java.util.List;
public class WeatherGradenTaskPlanner {
private final TaskList taskList;
WeatherService weatherService;
private final LocalDate dateSevereWeather = LocalDate.of(22,12,15);
public WeatherGradenTaskPlanner(TaskList taskList) {
this.taskList = taskList;
weatherService = new WeatherService();
}
public void getWeatherEvents() throws IOException {
Enum actualWeather = weatherService.causeSevereWeather(0);
if (SevereWeather.HAIL.equals(actualWeather)) {
createPreHail();
} else if (SevereWeather.FROST.equals(actualWeather)) {
createPreFrost();
} else if (SevereWeather.SNOW.equals(actualWeather)) {
createPreSnow();
}
}
public void createPreHail() throws IOException {
Task preHailTask = new Task("Hail",
"During a summer Thunderstorm it could hail heavily. THe Hail could damage the crops. To prevent damage cover the plants with a strong tarpaulin",
dateSevereWeather);
preHailTask.withId(Long.MAX_VALUE);
taskList.saveTask(preHailTask);
}
public void createPreFrost() throws IOException {
Task preFrostTask = new Task("Frost",
"The temperatur falls below zero degrees, cover especially the root with wool",
dateSevereWeather);
preFrostTask.withId(Long.MAX_VALUE);
taskList.saveTask(preFrostTask);
}
public void createPreSnow() throws IOException {
Task preSnowTask = new Task("Snow",
"The weather brings little snowfall. Cover your crops",
dateSevereWeather);
preSnowTask.withId(Long.MAX_VALUE);
taskList.saveTask(preSnowTask);
}
public void calculateRainAmount(){
}
public void adjustWateringTask(List<Crop> crops){
}
}

View File

@ -0,0 +1,14 @@
package ch.zhaw.gartenverwaltung.io;
public class WeatherService {
public Enum causeSevereWeather(int randomWeather){
return switch (randomWeather) {
case 1 -> SevereWeather.HAIL;
case 2 -> SevereWeather.SNOW;
case 3 -> SevereWeather.FROST;
default -> null;
};
}
}

View File

@ -33,6 +33,14 @@ public class Task {
this.startDate = startDate;
this.cropId = cropId;
}
/**
* Constructor for weather events
*/
public Task(String name, String description, LocalDate startDate) {
this.name = name;
this.description = description;
this.startDate = startDate;
}
public Task(String name, String description, LocalDate startDate, LocalDate endDate, int interval, long cropId) {
this.name = name;