Using For Loop with Weather Java Web Service

TheEvanElement

I have coded a way to get weather details from a WSDL webservice. My code works properly without any errors, but is there any way to use a For loop/while to get the three City and ZipCodes from the user?

The program should prompt for same information on the second, third and more cities by using, “for/while loop.”

How can I do this?

Here is the WSDL file:

`http://wsf.cdyne.com/WeatherWS/Weather.asmx?WSDL

Here is my code:

package weather;

import com.cdyne.ws.weatherws.ArrayOfWeatherDescription;
import com.cdyne.ws.weatherws.WeatherReturn;
import java.util.Scanner;

/**
 *
 * @author elacy
 */
public class Weather {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
      try {
        String zipCode1;
        String zipCode2;
        String zipCode3;
        Scanner keyboard = new Scanner(System.in);
        String City1;
        String City2;
        String City3;

        com.cdyne.ws.weatherws.Weather service = new com.cdyne.ws.weatherws.Weather();
        com.cdyne.ws.weatherws.WeatherSoap port = service.getWeatherSoap();

        \\makes this part a For loop

        System.out.println ("Please enter your First city");
        City1 = keyboard.nextLine().toUpperCase();
        System.out.println ("Please enter your First zipcode");
        zipCode1 = keyboard.nextLine();
        System.out.println ("Please enter your Second city");
        City2 = keyboard.nextLine().toUpperCase();
        System.out.println ("Please enter your Second zipcode");
        zipCode2 = keyboard.nextLine();
        System.out.println ("Please enter your Third city");
        City3 = keyboard.nextLine().toUpperCase();
        System.out.println ("Please enter your Third zipcode");
        zipCode3 = keyboard.nextLine();

        System.out.println("------------------------------------------------------");
        System.out.println("EVAN'S WEATHER FORECAST FOR: SUNDAY, OCTOBER 07, 2013");
        System.out.println("------------------------------------------------------");
        System.out.println("City   Zip   Code    Temp   Relative   Humidity");

       System.out.println(City1 +"   "+ zipCode1 + 
       port.getCityWeatherByZIP(zipCode1).getTemperature() +
       port.getCityWeatherByZIP(zipCode1).getRelativeHumidity());

       System.out.println(City2 +"   "+ zipCode2 +  
       port.getCityWeatherByZIP(zipCode2).getTemperature() +  
       port.getCityWeatherByZIP(zipCode2).getRelativeHumidity());

       System.out.println(City3 +"   "+ zipCode1 +
       port.getCityWeatherByZIP(zipCode3).getTemperature() +
       port.getCityWeatherByZIP(zipCode3).getRelativeHumidity());

       } catch (Exception ex) {
       }

     }

     private static WeatherReturn getCityWeatherByZIP(java.lang.String zip) {
       com.cdyne.ws.weatherws.Weather service = new com.cdyne.ws.weatherws.Weather();
       com.cdyne.ws.weatherws.WeatherSoap port = service.getWeatherSoap();
       return port.getCityWeatherByZIP(zip);
     }        
  }
Konstantin Yovkov

Pretty straightforward:

String[] cities = new String[3];
String[] zipCodes = new String[3];

for (int i = 0; i < 3; i++) {
    System.out.println ("Please enter your City No." + (i + 1) + ":");
    cities[i] = keyboard.nextLine().toUpperCase();
    System.out.println ("Please enter your Zipcode No." + (i + 1) + ":");
    zipCodes[i] = keyboard.nextLine();
}

System.out.println("------------------------------------------------------");
System.out.println("EVAN'S WEATHER FORECAST FOR: SUNDAY, OCTOBER 07, 2013");
System.out.println("------------------------------------------------------");
System.out.println("City   Zip   Code    Temp   Relative   Humidity");

for (int i = 0; i < 3; i++) {
    System.out.println(cities[i] +" " + zipCodes[i] + 
                    port.getCityWeatherByZIP(zipCodes[i]).getTemperature() + 
                    port.getCityWeatherByZIP(zipCodes[i]).getRelativeHumidity());
}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Securing REST Web Service using token (Java)

From Dev

Using Java web service on Amazon cloud

From Dev

Securing REST Web Service using token (Java)

From Dev

Memory leaks in a java web service using Hibernate

From Dev

Using Java web service on Amazon cloud

From Dev

Weather.asmx web service from JavaScript- No output returns

From Dev

Fetching weather data using java and the wunderground api

From Dev

How to check weather client is using PoolingHttpClientConnectionManager in java

From Dev

How to fix java web client services (weather) return unknown characters

From Dev

Using Specflow with a web service

From Dev

Upload File: Comsuming WCF Web Service Using Java

From Dev

SOAP Web service need to send request using https protocol in java

From Dev

Getting NullPointerException when consuming Java web service using PHP

From Dev

Web service using php soap server and java client

From Dev

How to export Java Web Service using Netbeans 8.0?

From Dev

Upload File: Comsuming WCF Web Service Using Java

From Dev

create new record into DB using java RESTful web service

From Dev

SOAP Web service need to send request using https protocol in java

From Dev

SSRS Render reports using JAVA and SOAP Web Service

From Dev

Proxy Java Web Service

From Dev

Java synchronization in web service

From Dev

Proxy Java Web Service

From Dev

Java to a web service and mysql

From Dev

Java synchronization in web service

From Dev

Using loop for web links

From Dev

Using loop for web links

From Dev

Creating input parameters and using java web service function in ASP.NET Web API

From Dev

Using yahoo weather Api

From Dev

Getting Hourly(Every 3 Hours in a day) Forecast using NOAA (National Weather Service)

Related Related

  1. 1

    Securing REST Web Service using token (Java)

  2. 2

    Using Java web service on Amazon cloud

  3. 3

    Securing REST Web Service using token (Java)

  4. 4

    Memory leaks in a java web service using Hibernate

  5. 5

    Using Java web service on Amazon cloud

  6. 6

    Weather.asmx web service from JavaScript- No output returns

  7. 7

    Fetching weather data using java and the wunderground api

  8. 8

    How to check weather client is using PoolingHttpClientConnectionManager in java

  9. 9

    How to fix java web client services (weather) return unknown characters

  10. 10

    Using Specflow with a web service

  11. 11

    Upload File: Comsuming WCF Web Service Using Java

  12. 12

    SOAP Web service need to send request using https protocol in java

  13. 13

    Getting NullPointerException when consuming Java web service using PHP

  14. 14

    Web service using php soap server and java client

  15. 15

    How to export Java Web Service using Netbeans 8.0?

  16. 16

    Upload File: Comsuming WCF Web Service Using Java

  17. 17

    create new record into DB using java RESTful web service

  18. 18

    SOAP Web service need to send request using https protocol in java

  19. 19

    SSRS Render reports using JAVA and SOAP Web Service

  20. 20

    Proxy Java Web Service

  21. 21

    Java synchronization in web service

  22. 22

    Proxy Java Web Service

  23. 23

    Java to a web service and mysql

  24. 24

    Java synchronization in web service

  25. 25

    Using loop for web links

  26. 26

    Using loop for web links

  27. 27

    Creating input parameters and using java web service function in ASP.NET Web API

  28. 28

    Using yahoo weather Api

  29. 29

    Getting Hourly(Every 3 Hours in a day) Forecast using NOAA (National Weather Service)

HotTag

Archive