Weather.java 810 B

123456789101112131415161718192021222324252627282930313233
  1. package weather;
  2. import java.util.Random;
  3. public class Weather {
  4. public enum Cloudage {
  5. clear, somewhatcloudy, cloudy, mostlycloudy, covered, rainy, stormy, apocalyptic;
  6. static Cloudage randomCloudage() {
  7. int rand = new Random().nextInt(Cloudage.values().length);
  8. return Cloudage.values()[rand];
  9. }
  10. }
  11. private String location;
  12. private int degrees;
  13. private int humidity;
  14. private Cloudage cloudage;
  15. public Weather(String location) {
  16. this.location = location;
  17. Random random = new Random();
  18. this.degrees = random.nextInt(50);
  19. this.humidity = random.nextInt(100);
  20. this.cloudage = Cloudage.randomCloudage();
  21. }
  22. @Override
  23. public String toString() {
  24. return String.format("%d °C %d%% humidity, %s @ %s", this.degrees, this.humidity, this.cloudage.name(), this.location);
  25. }
  26. }