
上QQ阅读APP看本书,新人免费读10天
设备和账号都新为新人
4.4 开发实践:温度和湿度数据的记录
4.4.1 开发设计
本任务通过一个Java程序来计算最近一周温度和湿度的平均值。在程序中定义了DataGenerater类,用于产生最近一周的温度和湿度数据。程序中模拟的数据如图4.2所示,程序执行流程如图4.3所示。

图4.2 程序中模拟的数据

图4.3 程序执行流程
4.4.2 功能实现
本任务的目标是计算最近一周温度和湿度的平均值,首先定义一个数组来保存最近一周的温度和湿度,然后取出数组中的数据进行累加求平均值。
1. 产生最近一周的温度和湿度

2. 定义并初始化存储温度和湿度的数组

通过DataGenerater类的getTemperatures方法与getHumiditys方法来初始化存储温度和湿度的数组。

3. 求最近一周温度和湿度的平均值并输出结果
