package?TianQiYuBao;
import?com.imooc.weather.HourWeather;
import?com.imooc.weather.WeatherUtils;
import?com.imooc.weather.impl.WeatherUtilsImpl;
import?java.util.List;
import?java.util.Scanner;
public?class?Application?{
????public?static?void?main(String[]?args)?{
????????System.out.println("輸入想要查詢的天氣:24小時。:三天。:七天。");
????????System.out.print("輸入你的選擇:");
????????Scanner?scanner?=?new?Scanner(System.in);
????????int?i?=?scanner.nextInt();
????????System.out.println("你輸入的是:"+i);
????????if?(i?==?24){
????????????System.out.print("輸入要查詢的城市名稱:");
????????????String?city?=?scanner.next();
????????????WeatherUtils?weatherUtils?=?new?WeatherUtilsImpl();
????????????List<HourWeather>?weatherList?=?weatherUtils.w24h("553d41feff124ac6a2fce95fc0810eba",city);
????????????//System.out.println(weatherList);
????????????if?(weatherList.size()?==?0){
????????????????System.out.println("抱歉,未查詢到您想要的數據。");
????????????}else{
????????????????for?(HourWeather?hourWeather?:?weatherList){
????????????????????String?template?=?"%s月%s日%s時|%s|%s|%s|%s@";
????????????????????String?row?=?String.format(template,new?String[]{
????????????????????????????hourWeather.getMonth(),
????????????????????????????hourWeather.getDay(),
????????????????????????????hourWeather.getHour(),
????????????????????????????hourWeather.getWindDirection(),
????????????????????????????hourWeather.getWindPower(),
????????????????????????????hourWeather.getWeather(),
????????????????????????????hourWeather.getTemperature()
????????????????????});
????????????????????System.out.println(row);
????????????????}
????????????}
????????}
????}
}



2021-07-18
2021-03-17
看一下購買的api是不是老師那個,如果不完全一樣,那就需要修改url