Skip to content

WeatherApp is a Java-based application that retrieves and displays global weather forecasts using the OpenWeatherMap API. Users can enter a city name to receive current weather information, including the city, country, time, and temperature.

Notifications You must be signed in to change notification settings

xinran0606/Wettervorhersagen_JavaVersion

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 

Repository files navigation

WeatherApp - Get Weather Forecasts Worldwide

WeatherApp is a Java-based application that retrieves and displays global weather forecasts using the OpenWeatherMap API. Users can enter a city name, and the program returns current weather information for that location, including the city, country, time, and temperature.

Features

  • City Search: Allows users to input any city name.
  • Live Data: Fetches real-time weather forecasts via the OpenWeatherMap API.
  • Detailed Output: Displays city, country, forecast time, and temperature.

Dependencies

  • OkHttp:Used for sending HTTP requests and retrieving weather data.
  • Gson:Used for parsing the JSON response from the API.

How to Run

Step 1: Get an API Key

  1. Go to the OpenWeatherMap website.
  2. Sign up and obtain a free API key. You will need this key to access the weather data.

Step 2: Configure the config.properties File

Create a file named config.properties in the root directory of the project with the following content:

API_URL=https://api.openweathermap.org/data/2.5/forecast
API_KEY=你的API密钥

Note: Replace YOUR_API_KEY with the actual key you obtained from OpenWeatherMap.

Step 3: Compile and Run the Program

1.Ensure you have the Java Development Kit (JDK) installed. 2.Download and include the OkHttp and Gson libraries in your classpath (via Maven, Gradle, or manual JARs). 3.Compile and run WeatherApp.java.

Example Commands (Terminal):

javac WeatherApp.java
java WeatherApp

(Note: On Linux/Mac, replace ; with : in the classpath)

Step 4: Enter City Name

Upon running, the application will prompt for a city name.

Example Output:

Enter city name: London
Request URL: https://api.openweathermap.org/data/2.5/forecast?q=London&appid=your-api-key&units=metric
City: London, Country: GB
Time: 2024-12-09 15:00:00, Temperature: 8.5°C
Time: 2024-12-09 18:00:00, Temperature: 7.8°C
Time: 2024-12-09 21:00:00, Temperature: 7.1°C
...

License

This project is licensed under the MIT License. You are free to use, modify, and distribute this project, provided you include the original copyright and license notice.

About

WeatherApp is a Java-based application that retrieves and displays global weather forecasts using the OpenWeatherMap API. Users can enter a city name to receive current weather information, including the city, country, time, and temperature.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages