forked from mouredev/retos-programacion-2023
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
49 additions
and
0 deletions.
There are no files selected for viewing
49 changes: 49 additions & 0 deletions
49
Retos/Reto #43 - SIMULADOR DE CLIMA [Fácil]/java/Qv1ko.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
|
||
} | ||
|
||
} |