Skip to content

Commit

Permalink
Reto mouredev#43 - Java
Browse files Browse the repository at this point in the history
  • Loading branch information
Qv1ko committed Oct 31, 2023
1 parent 128d200 commit 75b80f4
Showing 1 changed file with 49 additions and 0 deletions.
49 changes: 49 additions & 0 deletions Retos/Reto #43 - SIMULADOR DE CLIMA [Fácil]/java/Qv1ko.java
Original file line number Diff line number Diff line change
@@ -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);

}

}

0 comments on commit 75b80f4

Please sign in to comment.