From 75b80f47c03e592fa5bd1d7ab0c728953533ab73 Mon Sep 17 00:00:00 2001 From: Qv1ko Date: Tue, 31 Oct 2023 16:45:05 +0100 Subject: [PATCH] Reto #43 - Java --- .../java/Qv1ko.java" | 49 +++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 "Retos/Reto #43 - SIMULADOR DE CLIMA [F\303\241cil]/java/Qv1ko.java" diff --git "a/Retos/Reto #43 - SIMULADOR DE CLIMA [F\303\241cil]/java/Qv1ko.java" "b/Retos/Reto #43 - SIMULADOR DE CLIMA [F\303\241cil]/java/Qv1ko.java" new file mode 100644 index 0000000000..9ae25103e7 --- /dev/null +++ "b/Retos/Reto #43 - SIMULADOR DE CLIMA [F\303\241cil]/java/Qv1ko.java" @@ -0,0 +1,49 @@ +class Qv1ko { + + public static void main(String[] args) { + weather(9, 92, 7); + } + + private static void weather(int temperature, int rainProbability, int days) { + + rainProbability = Math.abs(rainProbability); + days = Math.abs(days); + + boolean rain = (int)(Math.random() * 100) < rainProbability; + int maxTemperature = temperature, minTemperature = temperature; + int rainyDays = 0; + int possibilities = 0; + + for (int i = 0; i < days; i++) { + + System.out.println("\nDay " + (i + 1) + ":\n Temperature: " + temperature + (rain ? "\n It rains" : "\n No rain")); + + if (temperature > maxTemperature) { + maxTemperature = temperature; + } else if (temperature < minTemperature) { + minTemperature = temperature; + } + rainyDays += rain ? 1 : 0; + + possibilities = (int)(Math.random() * 10); + + temperature += (possibilities == 1) ? 2 : (possibilities == 2) ? -2 : 0; + rainProbability += (temperature > 25) ? 20 : (temperature < 5) ? -20 : 0; + + if (rainProbability >= 100) { + temperature--; + rainProbability = 100; + } else if (rainProbability <= 0) { + temperature++; + rainProbability = 0; + } + + rain = (int)(Math.random() * 100) < rainProbability; + + } + + System.out.println("\nMaximum temperature: " + maxTemperature + "\nMinimum temperature: " + minTemperature + "\nRainy days: " + rainyDays); + + } + +}