Java final project
Java final project
PROGRAMMING
(22412)
MICRO-PROJECT
Academic year 2023-24
1
YADAVRAO TASGAONKAR POLYTECHNIC
MICRO PROJECT REPORT
Academic year: 2023-24
TITLE OF PROJECT
WEATHER FORECASTING
SUBMITTED BY:
1. Ronit Patil
2. Keval Chopade
3. Rushikesh kulkarni
SUBMITTED TO:
Yadhavrao tasgaonkar polytechnic bhivpuri For academic
year 2023-2024
2
Maharashtra State
Board of Technical Education
CERTIFICATE
Seal of
Institute
3
Maharashtra State
Board of Technical Education
CERTIFICATE
Seal of
Institute
4
Maharashtra State
Board of Technical Education
CERTIFICATE
Seal of
Institute
5
GROUP MEMBERS
6
INDEX
1 Aim of Project 8
2 Abstract 9
3 Introduction 10
4 Java Introduction 11
5 Methodology used 12
6 Resource Used 13
7 Advantages & Disadvantages 14
8 Coding 16
9 Output 18
10 Course outcome of project 19
11 Conclusion 20
12 Reference 21
7
AIM OF PROJECT
8
ABSTRACT
Weather forecasting plays a crucial role in various sectors, including
agriculture, transportation, disaster management, and everyday life
planning. This project aims to develop a weather forecasting system
using Java programming language, leveraging modern algorithms and
data processing techniques to provide accurate and timely predictions.
9
INTRODUCTION
Key Features:
1. Location-Based Weather Forecasts:
2. Real-Time Updates
3. Interactive Weather Maps
4. Customizable Alertsnformative Weather Widget
10
JAVA INTRODUCTION
11
METHODOLOGY USED
1. Requirement Analysis:
Define the scope and objectives of the weather forecasting project.
Gather requirements from stakeholders, including desired features and
functionalities.
2. Design Phase:
Define the architecture of the system, including components such as data
retrieval, data processing, and user interface.
Design class diagrams and sequence diagrams to illustrate the relationships
between different modules.
3. Data Acquisition:
Research and select suitable weather APIs or data sources to retrieve real-time
weather information.
Implement methods to fetch weather data from APIs using HTTP requests or
other networking protocols.
Handle authentication (if required) and error cases gracefully to ensure robust
data retrieval.
4. Data Processing:
Parse the retrieved weather data into Java objects or data structures for further
analysis.
Implement algorithms to process raw weather data and generate forecasts based
on historical patterns or machine learning models.
Apply error handling mechanisms to deal with invalid or incomplete data
received from external sources.
12
Resource Used
2 Software Visual-Studio(2017) 1
,MS Word
3 Hardware i-5 5th gen 1
13
ADVANTAGES & DISADVANTAGES
Advantages:
14
Disadvantages:
15
CODING
import java.io.IOException;
import java.net.HttpURLConnection; import java.net.URL;
import java.util.Scanner;
import org.json.JSONArray; import org.json.JSONObject;
public class weatherforecast {
private static final String API_KEY = "5daf72db790a92c92ceffa99821046d3"; private static
final String BASE_URL =
"http://api.openweathermap.org/data/2.5/forecast?q=";
public static void main(String[] args) { String city = "Delhi"; // Example city
String urlString = BASE_URL + city + "&appid=" + API_KEY + "&units=metric";
try {
String data = fetchWeatherData(urlString); if (data != null) {
parseAndDisplayWeatherData(data);
}
} catch (IOException e) { e.printStackTrace();
}
}
public static String fetchWeatherData(String urlString) throws IOException { URL url = new
URL(urlString);
StringBuilder data = new StringBuilder();
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("GET");
conn.connect();
int responseCode = conn.getResponseCode();
if (responseCode != 200) {
throw new RuntimeException("HttpResponseCode: " + responseCode);
} else {
Scanner scanner = new Scanner(url.openStream()); while (scanner.hasNext()) {
data.append(scanner.nextLine());
}
scanner.close();
16
}
return data.toString();
}
public static void parseAndDisplayWeatherData(String data) { JSONObject jsonObject = new
JSONObject(data); JSONArray weatherArray = jsonObject.getJSONArray("list");
for (int i = 0; i < weatherArray.length(); i++) {
JSONObject weatherObject = weatherArray.getJSONObject(i); JSONObject main =
weatherObject.getJSONObject("main");
double temp = main.getDouble("temp");
double tempMin = main.getDouble("temp_min"); double tempMax =
main.getDouble("temp_max"); double humidity = main.getDouble("humidity"); String dateTime
= weatherObject.getString("dt_txt");
System.out.println("Date/Time: " + dateTime); System.out.println("Temperature: " + temp +
"°C"); System.out.println("Min Temperature: " + tempMin + "°C"); System.out.println("Max
Temperature: " + tempMax + "°C"); System.out.println("Humidity: " + humidity + "%");
System.out.println(" ");
}
}
}
17
OUTPUT
18
Course outcomes for a project
1. Understanding of API Integration: Students will gain proficiency in
integrating third-party APIs, such as the OpenWeatherMap API, to fetch
real-time weather data for various locations globally.
19
CONCLUSION
20
Reference
1. https://www.google.com/
2. https://chat.openai.com/
3. https://www.wikipedia.org/
21