Weather Forecaster Ap in Java Applet: JavaFX for the UI and you can set up the U
ID: 3731087 • Letter: W
Question
Weather Forecaster Ap in
Java Applet: JavaFX for the UI and you can set up the UI using fxml files or pure Java code
Goal: Create an app to display a weather forecast for the user’s current location,
Create the app titled Weather Forecaster
The first screen will have a textbox for the user to enter a zip code and a button to submit
When the user enters the zip code and clicks the button, the app will navigate to the weather forecast screen.
The weather forecast screen will show the current weather for the user’s location in a label
Input validation for the zip code (only valid zip codes should be accepted)
Display a listview/tableview of the forecast for the next 7 days
Display High Temp, Low Temp, Humidity Pressure Sunrise and Sun Set
Display images for the forecast (eg: clouds for cloudy weather, a sun for clear weather)
Get the weather using an async task
Use the user’s current location from the device GPS (for this functionality, the app does not need the zip code entry in the first screen)
Database: Store location in database, and allow it to be updated via JDBC
Some publicly available weather APIs (any API is acceptable):
http://openweathermap.org/api
https://developer.yahoo.com/weather/
http://graphical.weather.gov/xml/
Explanation / Answer
Since this is very big assignment, it is impossible to complete this assignment within 2 hours (the time the experts get to solve a problem).
Here, I am providing the code for a very basic Weather app which user the
You can incrementally add the features over this code as per you requirements.
WeatherDoc.java
***********************************
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintStream;
import java.net.URL;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import org.w3c.dom.Document;
public class WeatherDoc
{
public WeatherDoc(String WOEID, String IM)
{
WeatherDisplay disp = new WeatherDisplay();
try
{
Document doc = generateXML(WOEID, IM);
disp.getConditions(doc);
}
catch (IOException ex)
{
Logger.getLogger(WeatherDoc.class.getName()).log(Level.SEVERE, null, ex);
}
}
public static Document generateXML(String code, String IM)
throws IOException
{
String url = null;
String XmlData = null;
url = "http://xml.weather.yahoo.com/forecastrss?w=" + code + "&u=" + IM;
URL xmlUrl = new URL(url);
InputStream in = xmlUrl.openStream();
Document doc = parse(in);
return doc;
}
public static Document parse(InputStream is)
{
Document doc = null;
try
{
DocumentBuilderFactory domFactory = DocumentBuilderFactory.newInstance();
domFactory.setValidating(false);
domFactory.setNamespaceAware(false);
DocumentBuilder builder = domFactory.newDocumentBuilder();
doc = builder.parse(is);
}
catch (Exception ex) {
System.err.println("unable to load XML: " + ex);
}
return doc;
}
}
WeatherDisplay.java
**************************************
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.