Advertisement
Guest User

Test

a guest
Mar 31st, 2020
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.13 KB | None | 0 0
  1.  
  2. import core.data.*;
  3.  
  4. public class Welcome02_Object {
  5.    public static void main(String[] args) {
  6.       String id1 = "KATL";
  7.       DataSource ds1 = DataSource.connect("http://weather.gov/xml/current_obs/" + id1 + ".xml");
  8.       ds1.setCacheTimeout(15 * 60);  
  9.       ds1.load();
  10.       //ds1.printUsageString();
  11.  
  12.       Observation ob1 = ds1.fetch("Observation", "weather", "temp_f", "wind_degrees");
  13.       System.out.println(id1 + ": " + ob1);
  14.      
  15.       String id2 = "KSAV";
  16.       DataSource ds2 = DataSource.connect("http://weather.gov/xml/current_obs/" + id2 + ".xml");
  17.       ds2.setCacheTimeout(15 * 60);  
  18.       ds2.load();
  19.      
  20.       Observation ob2 = ds2.fetch("Observation", "weather", "temp_f", "wind_degrees");
  21.       System.out.println(id2 + ": " + ob2);
  22.      
  23.       String id3 = "KSEA";
  24.       DataSource ds3 = DataSource.connect("http://weather.gov/xml/current_obs/" + id3 + ".xml");
  25.       ds3.setCacheTimeout(15 * 60);  
  26.       ds3.load();
  27.      
  28.       Observation ob3 = ds3.fetch("Observation", "weather", "temp_f", "wind_degrees");
  29.       System.out.println(id3 + ": " + ob3);
  30.      
  31.      
  32.       if (ob1.colderThan(ob2) && ob1.colderThan(ob3)) {
  33.          System.out.println("Colder at " + id1);
  34.       } else {
  35.          if(ob2.colderThan(ob3))
  36.          {
  37.          System.out.println("Colder at " + id2);
  38.          }
  39.          else
  40.          {
  41.             System.out.println("Colder at " + id3);
  42.          }
  43.       }
  44.    }
  45. }
  46.  
  47.  
  48. /* Represents a weather observation */
  49. class Observation {
  50.    float temp;    // in fahrenheit
  51.    int windDir;   // in degrees
  52.    String description;
  53.    
  54.    Observation(String description, float temp, int windDir) {
  55.       this.description = description;
  56.       this.temp = temp;
  57.       this.windDir = windDir;
  58.    }
  59.    
  60.    /* determine if the temperature of this observation is colder than 'that's */
  61.    public boolean colderThan(Observation that) {
  62.       return this.temp < that.temp;
  63.    }
  64.    
  65.    /* produce a string describing this observation */
  66.    public String toString() {
  67.       return (temp + " degrees; " + description + " (wind: " + windDir + " degrees)");
  68.    }
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement