Java第十六次作业(天气预报查询)

先在浏览器里面搜索阿里云官网

注册登录后

搜索天气预报

找到免费的

购买

 点里面管理控制台里面有阿里云的code等等,这个要记住

 上面有调试

 

 

 实现24小时天气预报查询

 新建一个目录

package weatherlj;



		
		 
		import java.util.List;
		import java.util.Scanner;
		 
		public class Application {
		    public static void main(String[] args) {
		        System.out.println("查询最近天气预报:");
		        System.out.println("输入1:查询未来24小时天气预报:");
		        System.out.println("输入2:查询未来3天天气预报");
		        System.out.println("输入3:查询未来7天天气预报");
		        System.out.print("请输入您的选择:");
		        Scanner scanner = new Scanner(System.in);
		        int i = scanner.nextInt();
		        System.out.println("用户输入数字:" + i);
		        if(i==1){
		            System.out.print("请输入城市名称查询未来24小时天气预报:");
		            String city = scanner.next();
		           
		 
		    }
		}
	

目录为lib

 在目录上右键粘贴文件

 

 点击file 找到下面的

 

 再点ok

这里有很多开发好了的

 代码如下

package com.imooc.weather;
 
import java.util.List;
import java.util.Scanner;
import com.imooc.weather.impl.WeatherUtilsImpl;
 
public class Application {
    public static void main(String[] args) {
        System.out.println("查询最近天气预报:");
        System.out.println("输入1:查询未来24小时天气预报");
        System.out.println("输入2:查询未来3天天气预报");
        System.out.println("输入3:查询未来7天天气预报");
        System.out.print("请输入您的选择:");
        Scanner scanner = new Scanner(System.in);
        int i = scanner.nextInt();
        System.out.println("用户输入数字:" + i);
        if (i==1){
            System.out.print("请输入城市名称查询未来24小时天气预报:");
            String city = scanner.next();
            WeatherUtils weatherUtils = new WeatherUtilsImpl();
            List<HourWeather> weatherList = weatherUtils.w24h("fc353f2cc78f49b5ba91cf096337c08e",city);//API输入自己的api应用程序编程接口,这里就不提供了!
            System.out.println(weatherList);
            if (weatherList.size() == 0){
                System.out.println("抱歉,未收录您查询的城市天气数据。");
            }else{
                for (HourWeather hourWeather : weatherList){
                    String template = "%s月%s日%s时|%-3s|%-20s|%-8s|%-4s℃";
                    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);
                }
            }
        } else if (i==2) {
            System.out.print("请输入城市名称查询未来3天天气预报:");
            String city = scanner.next();
            WeatherUtils weatherUtils = new WeatherUtilsImpl();
            List<DayWeather> weatherList = weatherUtils.w3d("fc353f2cc78f49b5ba91cf096337c08e", city);//API输入自己的api应用程序编程接口
System.out.println(weatherList.size());
            if (weatherList.size() == 0) {
                System.out.println("抱歉,未收录您查询的城市天气数据。");
            } else {
                for (DayWeather weather : weatherList) {
                    String template = "%-2s月%-2s日 | 气温: %s℃(日) %s℃(夜) | 天气: %s(日) %s(夜) | 风力: %s(日) %s(夜)";
                    String row = String.format(template, new String[]{
                            weather.getMonth(),
                            weather.getDay(),
                            weather.getDayAirTemperature(),
                            weather.getNightAirTemperature(),
                            weather.getDayWeather(),
                            weather.getNightWeather(),
                            weather.getDayWindPower(),
                            weather.getNightWindPower()
                    });
                    System.out.println(row);
                }
            }
        }else if (i==3) {
            System.out.print("请输入城市名称查询未来7天天气预报:");
            String city = scanner.next();
            WeatherUtils weatherUtils = new WeatherUtilsImpl();
            List<DayWeather> weatherList = weatherUtils.w7d("fc353f2cc78f49b5ba91cf096337c08e", city);//API输入自己的api应用程序编程接口
            System.out.println(weatherList.size());
            if (weatherList.size() == 0) {
                System.out.println("抱歉,未收录您查询的城市天气数据。");
            } else {
                for (DayWeather weather : weatherList) {
                    String template = "%-2s月%-2s日 | 气温: %s℃(日) %s℃(夜) | 天气: %s(日) %s(夜) | 风力: %s(日) %s(夜)";
                    String row = String.format(template, new String[]{
                            weather.getMonth(),
                            weather.getDay(),
                            weather.getDayAirTemperature(),
                            weather.getNightAirTemperature(),
                            weather.getDayWeather(),
                            weather.getNightWeather(),
                            weather.getDayWindPower(),
                    weather.getNightWindPower()
                    });
                    System.out.println(row);
                }
            }
        }
    }
}

输出24小时

 

 输出3天

 输出7天

  • 0
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

遇見即是上上籤

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值