我编写了一种从 WSDL Web 服务获取天气详细信息的方法。我的代码可以正常工作,没有任何错误,但是有没有办法使用 For 循环/while 从用户那里获取三个 City 和 ZipCodes?
程序应使用“for/while 循环”提示有关第二个、第三个和更多城市的相同信息。</p>
我怎样才能做到这一点?
这是 WSDL 文件:
` http://wsf.cdyne.com/WeatherWS/Weather.asmx?WSDL
这是我的代码:
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);
}
}