Question: Add the features below to the following code to reach the goal Goal: Goal: Create an app to display a weather forecast for the users

Add the features below to the following code to reach the goal

Goal: Goal: Create an app to display a weather forecast for the users current location

Features:

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 users 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 users 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

Include screen shots of working application

Starting Code

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

**************************************

import org.w3c.dom.Document;

import org.w3c.dom.Element;

import org.w3c.dom.Node;

import org.w3c.dom.NodeList;

public class WeatherDisplay

{

public static String city;

public static String country;

public static String temperature;

public static String condition;

public static String humidity;

public static String visibility;

public static String pressure;

public static String rising;

public static String sunrise;

public static String sunset;

public static String chill;

public static String direction;

public static String speed;

public static String tempUnit;

public static String distanceUnit;

public static String pressureUnit;

public static String speedUnit;

public WeatherDisplay() {}

public void getConditions(Document doc)

{

try

{

doc.getDocumentElement().normalize();

NodeList nList = doc.getElementsByTagName("rss");

for (int temp = 0; temp < nList.getLength(); temp++)

{

Node nNode = nList.item(temp);

if (nNode.getNodeType() == 1)

{

Element eElement = (Element)nNode;

NodeList nl = eElement.getElementsByTagName("yweather:location");

for (int tempr = 0; tempr < nl.getLength(); tempr++)

{

Node n = nl.item(tempr);

if (nNode.getNodeType() == 1)

{

Element e0 = (Element)n;

city = e0.getAttribute("city");

}

if (nNode.getNodeType() == 1)

{

Element e1 = (Element)n;

country = e1.getAttribute("country");

}

}

NodeList nl2 = eElement.getElementsByTagName("yweather:units");

for (int tempr = 0; tempr < nl2.getLength(); tempr++)

{

Node n2 = nl2.item(tempr);

if (nNode.getNodeType() == 1)

{

Element e2 = (Element)n2;

tempUnit = e2.getAttribute("temperature");

}

if (nNode.getNodeType() == 1)

{

Element e2 = (Element)n2;

distanceUnit = e2.getAttribute("distance");

}

if (nNode.getNodeType() == 1)

{

Element e2 = (Element)n2;

pressureUnit = e2.getAttribute("pressure");

}

if (nNode.getNodeType() == 1)

{

Element e2 = (Element)n2;

speedUnit = e2.getAttribute("speed");

}

}

NodeList nl3 = eElement.getElementsByTagName("yweather:condition");

for (int tempr = 0; tempr < nl3.getLength(); tempr++)

{

Node n3 = nl3.item(tempr);

if (nNode.getNodeType() == 1)

{

Element e3 = (Element)n3;

temperature = e3.getAttribute("temp");

}

if (nNode.getNodeType() == 1)

{

Element e3 = (Element)n3;

condition = e3.getAttribute("text");

}

}

NodeList nl4 = eElement.getElementsByTagName("yweather:atmosphere");

for (int tempr = 0; tempr < nl4.getLength(); tempr++)

{

Node n4 = nl4.item(tempr);

if (nNode.getNodeType() == 1)

{

Element e4 = (Element)n4;

humidity = e4.getAttribute("humidity");

}

if (nNode.getNodeType() == 1)

{

Element e4 = (Element)n4;

visibility = e4.getAttribute("visibility");

}

if (nNode.getNodeType() == 1)

{

Element e4 = (Element)n4;

pressure = e4.getAttribute("pressure");

}

if (nNode.getNodeType() == 1)

{

Element e4 = (Element)n4;

rising = e4.getAttribute("rising");

}

}

NodeList nl5 = eElement.getElementsByTagName("yweather:astronomy");

for (int tempr = 0; tempr < nl5.getLength(); tempr++)

{

Node n5 = nl5.item(tempr);

if (nNode.getNodeType() == 1)

{

Element e5 = (Element)n5;

sunrise = e5.getAttribute("sunrise");

}

if (nNode.getNodeType() == 1)

{

Element e5 = (Element)n5;

sunset = e5.getAttribute("sunset");

}

}

NodeList nl6 = eElement.getElementsByTagName("yweather:wind");

for (int tempr = 0; tempr < nl6.getLength(); tempr++)

{

Node n6 = nl6.item(tempr);

if (nNode.getNodeType() == 1)

{

Element e6 = (Element)n6;

chill = e6.getAttribute("chill");

}

if (nNode.getNodeType() == 1)

{

Element e6 = (Element)n6;

direction = e6.getAttribute("direction");

}

if (nNode.getNodeType() == 1)

{

Element e6 = (Element)n6;

speed += e6.getAttribute("speed");

speed = e6.getAttribute("speed");

}

}

}

}

}

catch (Exception e)

{

e.printStackTrace();

}

}

public String getCity()

{

return city;

}

public String getCountry()

{

return country;

}

public String getTemperature()

{

return temperature;

}

public String getCondition()

{

return condition;

}

public String getHumidity()

{

return humidity;

}

public String getVisibility()

{

return visibility;

}

public String getPressure()

{

return pressure;

}

public String getRising()

{

return rising;

}

public String getSunrise()

{

return sunrise;

}

public String getSunset()

{

return sunset;

}

public String getWindChill()

{

return chill;

}

public String getWindDirection()

{

return direction;

}

public String getWindSpeed()

{

return speed;

}

public String getDistanceUnit()

{

return distanceUnit;

}

public String getPressureUnit()

{

return pressureUnit;

}

public String getTemperatureUnit()

{

return tempUnit;

}

public String getSpeedUnit()

{

return speedUnit;

}

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!