Advertisement
erwinprasetyo97

WeatherItems.java

Aug 19th, 2018
334
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.84 KB | None | 0 0
  1. package com.erprasetyo.myasynctaskloader;
  2.  
  3. import org.json.JSONObject;
  4.  
  5. import java.text.DecimalFormat;
  6.  
  7. public class WeatherItems {
  8. private int id;
  9. private String nama;
  10. private String curentWeather;
  11. private String description;
  12. private String temperature;
  13.  
  14. public WeatherItems(JSONObject object) {
  15. try {
  16. int id = object.getInt("id");
  17. String name = object.getString("name");
  18. String currentWeather = object.getJSONArray("weather").getJSONObject(0).getString("main");
  19. double tempInKelvin = object.getJSONObject("main").getDouble("temp");
  20.  
  21. double tempInCelsius = tempInKelvin - 273;
  22. String temperature = new DecimalFormat("##.##").format(tempInCelsius);
  23.  
  24. this.id = id;
  25. this.nama = name;
  26. this.curentWeather = currentWeather;
  27. this.description = description;
  28. this.temperature = temperature;
  29.  
  30. } catch (Exception e) {
  31. e.printStackTrace();
  32. }
  33. }
  34.  
  35. public int getId() {
  36. return id;
  37. }
  38.  
  39. public void setId(int id) {
  40. this.id = id;
  41. }
  42.  
  43. public String getNama() {
  44. return nama;
  45. }
  46.  
  47. public void setNama(String nama) {
  48. this.nama = nama;
  49.  
  50. }
  51.  
  52. public String getCurentWeather() {
  53. return curentWeather;
  54. }
  55.  
  56. public void setCurentWeather(String currentWeather) {
  57. this.curentWeather = currentWeather;
  58. }
  59.  
  60. public String getDescription() {
  61. return description;
  62.  
  63. }
  64.  
  65. public void setDescription(String description) {
  66. this.description = description;
  67. }
  68.  
  69. public String getTemperature() {
  70. return temperature;
  71. }
  72.  
  73. public void setTemperature(String temperature) {
  74. this.temperature = temperature;
  75. }
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement