123456789101112131415161718192021222324252627282930313233 |
- package weather;
- import java.util.Random;
- public class Weather {
- public enum Cloudage {
- clear, somewhatcloudy, cloudy, mostlycloudy, covered, rainy, stormy, apocalyptic;
-
- static Cloudage randomCloudage() {
- int rand = new Random().nextInt(Cloudage.values().length);
- return Cloudage.values()[rand];
- }
- }
-
- private String location;
- private int degrees;
- private int humidity;
- private Cloudage cloudage;
-
- public Weather(String location) {
- this.location = location;
- Random random = new Random();
- this.degrees = random.nextInt(50);
- this.humidity = random.nextInt(100);
- this.cloudage = Cloudage.randomCloudage();
- }
-
- @Override
- public String toString() {
- return String.format("%d °C %d%% humidity, %s @ %s", this.degrees, this.humidity, this.cloudage.name(), this.location);
- }
- }
|