From 192fa2e042eaada7c16294c40f1740494c719da2 Mon Sep 17 00:00:00 2001 From: Mahla Date: Wed, 1 Mar 2023 12:16:33 +0330 Subject: [PATCH 1/5] Completed the dependencies section --- build.gradle | 2 ++ 1 file changed, 2 insertions(+) diff --git a/build.gradle b/build.gradle index cfc21e9..a6e550c 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: '20220924' } From 7417b18afe0342e973c70d50e57da50b44622cba Mon Sep 17 00:00:00 2001 From: Mahla Date: Wed, 1 Mar 2023 12:51:55 +0330 Subject: [PATCH 2/5] test --- src/main/java/WeatherApp.java | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/src/main/java/WeatherApp.java b/src/main/java/WeatherApp.java index 8cecccd..219416d 100644 --- a/src/main/java/WeatherApp.java +++ b/src/main/java/WeatherApp.java @@ -7,12 +7,19 @@ public class WeatherApp { // Copy your API-KEY here - public final static String apiKey = "API-KEY"; - // TODO: Write main function - public static void main(String[] args) { + public final static String apiKey = "67282eb9cedb48bf9dc72207230103"; +// TODO: Write main function + public static void main(String[] args) { + Scanner in = new Scanner(System.in); + String city; + city = in.next(); + String WeatherData = getWeatherData(city); + double Temp = getTemperature(WeatherData); + System.out.println(Temp); + int Hum = getHumidity(WeatherData); + System.out.println(Hum); } - /** * Retrieves weather data for the specified city. * @@ -32,7 +39,8 @@ public static String getWeatherData(String city) { } reader.close(); return stringBuilder.toString(); - } catch (Exception e) { + } + catch (Exception e) { e.printStackTrace(); return null; } @@ -41,12 +49,16 @@ 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; } } From 24f7a8a65d01c762c2f7bd56130c7aa0119858ba Mon Sep 17 00:00:00 2001 From: Mahla Date: Wed, 1 Mar 2023 23:24:39 +0330 Subject: [PATCH 3/5] Report --- src/main/java/Report.md | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 src/main/java/Report.md diff --git a/src/main/java/Report.md b/src/main/java/Report.md new file mode 100644 index 0000000..4b3ab28 --- /dev/null +++ b/src/main/java/Report.md @@ -0,0 +1,16 @@ +# Second-Assignment Report! + +## Introduction +- This application is made to give us the temperature and humidity of a city\ +by taking the name of the city. +- The purpose of this assignment is probably to learn how to work with Git and GitHub. + +## Design and Implementation +- In this program, I did not use any special data structure except +that I got acquainted with json data structure. + +## Testing and Evaluation + + +## Conclusion + From a9aeb13c12c95f22aec828a7d57c6e7e67be09c9 Mon Sep 17 00:00:00 2001 From: Mahla Date: Wed, 1 Mar 2023 23:47:33 +0330 Subject: [PATCH 4/5] Report --- src/main/java/Report.md | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/main/java/Report.md b/src/main/java/Report.md index 4b3ab28..46123ec 100644 --- a/src/main/java/Report.md +++ b/src/main/java/Report.md @@ -8,9 +8,20 @@ by taking the name of the city. ## Design and Implementation - In this program, I did not use any special data structure except that I got acquainted with json data structure. +- The algorithm I used in this question was to take the city name as a string and then +give it to two functions that return the temperature and humidity of that city. +At the beginning, +I entered the API Key that it can connect with the Weather site. +- The challenge I faced was working with Git because it was my first time using it +and I didn't know its commands. ## Testing and Evaluation - - +- To check if the program works properly and gives the right output, +I gave it the city of Tehran as input +and it returned its temperature and humidity as output. ## Conclusion - +- I learned to work with Markdown +and it was beautiful and simple and of course practical. +- Actually , I don't see any strong point because I didn't do anything special, +but there was a lot of way to improve the solution and increase its strengths. +Hopefully next time! From 333ed76552c0e15477111b701843ea6f5a2e8a1d Mon Sep 17 00:00:00 2001 From: Mahla Date: Wed, 1 Mar 2023 23:50:18 +0330 Subject: [PATCH 5/5] Report --- src/main/java/Report.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/Report.md b/src/main/java/Report.md index 46123ec..d02365b 100644 --- a/src/main/java/Report.md +++ b/src/main/java/Report.md @@ -24,4 +24,4 @@ and it returned its temperature and humidity as output. and it was beautiful and simple and of course practical. - Actually , I don't see any strong point because I didn't do anything special, but there was a lot of way to improve the solution and increase its strengths. -Hopefully next time! +next time Inshallah!