From 670938ef85844b77b6a38d5e0d5880aa74dcbec6 Mon Sep 17 00:00:00 2001 From: Gian-Andrea Hutter Date: Tue, 22 Nov 2022 14:44:56 +0100 Subject: [PATCH] #23 added constructor in Task class, implemented SevereWeather, WeatherService, WeatherGradenTaskPlanner --- .../gartenverwaltung/io/SevereWeather.java | 5 ++ .../io/WeatherGradenTaskPlanner.java | 64 +++++++++++++++++++ .../gartenverwaltung/io/WeatherService.java | 14 ++++ .../ch/zhaw/gartenverwaltung/types/Task.java | 8 +++ 4 files changed, 91 insertions(+) create mode 100644 src/main/java/ch/zhaw/gartenverwaltung/io/SevereWeather.java create mode 100644 src/main/java/ch/zhaw/gartenverwaltung/io/WeatherGradenTaskPlanner.java create mode 100644 src/main/java/ch/zhaw/gartenverwaltung/io/WeatherService.java diff --git a/src/main/java/ch/zhaw/gartenverwaltung/io/SevereWeather.java b/src/main/java/ch/zhaw/gartenverwaltung/io/SevereWeather.java new file mode 100644 index 0000000..d76036f --- /dev/null +++ b/src/main/java/ch/zhaw/gartenverwaltung/io/SevereWeather.java @@ -0,0 +1,5 @@ +package ch.zhaw.gartenverwaltung.io; + +public enum SevereWeather { + FROST,SNOW,HAIL,NO_SEVERE_WEATHER +} diff --git a/src/main/java/ch/zhaw/gartenverwaltung/io/WeatherGradenTaskPlanner.java b/src/main/java/ch/zhaw/gartenverwaltung/io/WeatherGradenTaskPlanner.java new file mode 100644 index 0000000..ec8dd48 --- /dev/null +++ b/src/main/java/ch/zhaw/gartenverwaltung/io/WeatherGradenTaskPlanner.java @@ -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 crops){ + + } +} diff --git a/src/main/java/ch/zhaw/gartenverwaltung/io/WeatherService.java b/src/main/java/ch/zhaw/gartenverwaltung/io/WeatherService.java new file mode 100644 index 0000000..fffe1bc --- /dev/null +++ b/src/main/java/ch/zhaw/gartenverwaltung/io/WeatherService.java @@ -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; + }; + + } +} diff --git a/src/main/java/ch/zhaw/gartenverwaltung/types/Task.java b/src/main/java/ch/zhaw/gartenverwaltung/types/Task.java index df15fc4..a2bc6a0 100644 --- a/src/main/java/ch/zhaw/gartenverwaltung/types/Task.java +++ b/src/main/java/ch/zhaw/gartenverwaltung/types/Task.java @@ -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;