From e18197e45fd48b048da23eefffb3e1adcc15f4c6 Mon Sep 17 00:00:00 2001 From: Hasti Javadzadeh Date: Wed, 1 Mar 2023 11:50:50 +0330 Subject: [PATCH 1/4] filled the dependencies section --- build.gradle | 2 ++ 1 file changed, 2 insertions(+) diff --git a/build.gradle b/build.gradle index cfc21e9..2cf926e 100644 --- a/build.gradle +++ b/build.gradle @@ -12,6 +12,8 @@ repositories { dependencies { testImplementation 'org.junit.jupiter:junit-jupiter-api:5.8.1' testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.8.1' + // https://mvnrepository.com/artifact/org.json/json + implementation group: 'org.json', name: 'json', version: '20230227' } From 4de5ab41fb152f0db151c792dac589aa47cf0e2d Mon Sep 17 00:00:00 2001 From: Hasti Javadzadeh Date: Wed, 1 Mar 2023 12:47:58 +0330 Subject: [PATCH 2/4] done --- src/main/java/WeatherApp.java | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/src/main/java/WeatherApp.java b/src/main/java/WeatherApp.java index 8cecccd..5cb4cc2 100644 --- a/src/main/java/WeatherApp.java +++ b/src/main/java/WeatherApp.java @@ -7,10 +7,16 @@ public class WeatherApp { // Copy your API-KEY here - public final static String apiKey = "API-KEY"; + public final static String apiKey = "67a6c2c3591e4e10839152337232502"; // TODO: Write main function public static void main(String[] args) { + Scanner input = new Scanner(System.in); + String city = input.nextLine(); + System.out.println("Temperature = " + getTemperature(getWeatherData(city))); + System.out.println("Humidity = " + getHumidity(getWeatherData(city))); + System.out.println("Wind speed = " + getWindSpeed(getWeatherData(city))); + System.out.println("Wind direction = " + getWindDir(getWeatherData(city))); } /** @@ -41,12 +47,32 @@ public static String getWeatherData(String city) { // TODO: Write getTemperature function returns celsius temperature of city by given json string public static double getTemperature(String weatherJson){ double answer = 0.0; + JSONObject data = new JSONObject(weatherJson); + answer = data.getJSONObject("current").getDouble("temp_c"); return answer; } // TODO: Write getHumidity function returns humidity percentage of city by given json string public static int getHumidity(String weatherJson){ int answer = 0; + JSONObject data = new JSONObject(weatherJson); + answer = data.getJSONObject("current").getInt("humidity"); return answer; } + + public static double getWindSpeed(String weatherJson){ + double answer = 0.0; + JSONObject data = new JSONObject(weatherJson); + answer = data.getJSONObject("current").getDouble("wind_mph"); + return answer; + } + + public static String getWindDir(String weatherJson){ + String answer; + JSONObject data = new JSONObject(weatherJson); + answer = data.getJSONObject("current").getString("wind_dir"); + return answer; + } + + } From 5d7fc0c5f122f0658d11d8a22622506b4cc670fc Mon Sep 17 00:00:00 2001 From: Hasti Javadzadeh Date: Wed, 1 Mar 2023 22:49:22 +0330 Subject: [PATCH 3/4] my report --- report.md | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 report.md diff --git a/report.md b/report.md new file mode 100644 index 0000000..830e11f --- /dev/null +++ b/report.md @@ -0,0 +1,9 @@ +# Weather app assignment +## Introduction +In this assignment, we built a simple Java application that connects to a weather API and retrieves information about the current weather conditions of a given city. +## Design and Implemention +At first the city's name is passed to the getWeatherData method and it returns a string.Then the string is passed to getTemperature(or getHumidity, etc) method and we can get the information we want. +## Testing and Evaluation +To make sure the program works properly, I checked the results with the correct weather information of that city. +## Conclusion +This assignment helped me to lean how to use JSON objects. From fece287472da98e6b71d80773e95611c0c915da4 Mon Sep 17 00:00:00 2001 From: hastiJavadzadeh <125308675+hastiJavadzadeh@users.noreply.github.com> Date: Wed, 1 Mar 2023 22:50:43 +0330 Subject: [PATCH 4/4] Update report.md --- report.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/report.md b/report.md index 830e11f..ce60c7b 100644 --- a/report.md +++ b/report.md @@ -6,4 +6,4 @@ At first the city's name is passed to the getWeatherData method and it returns a ## Testing and Evaluation To make sure the program works properly, I checked the results with the correct weather information of that city. ## Conclusion -This assignment helped me to lean how to use JSON objects. +This assignment helped me to learn how to use JSON objects.