现提供某股票在2014-2020的交易信息,数据文件的各个列的说明如下:(数据见附件stocks.csv) trade_date 交易时间 open 开盘价格 high 当日最高价 low 当日最低价 close 收盘价 amount 交易量 统计该股票各个月的波动范围(本月的收盘最低价-本月的收盘最高价),波动率(波动范围/本月收盘价平均价格,保留小数点后2位数字),以及这个月的总成交量输出结果如下: 2019.6 69.64-72.07 3.55% 127897.5 本题可在本地hadoop虚拟环境中验证执行,需提交关键代码的源码截图和执行结果截图,并附带工程源码(提交压缩包) 用java写出代码并给出pom.xml文件


代码如下: ```java import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.fs.Path; import org.apache.hadoop.io.FloatWritable; import org.apache.hadoop.io.Text; import org.apache.hadoop.mapreduce.Job; import org.apache.hadoop.mapreduce.Mapper; import org.apache.hadoop.mapreduce.Reducer; import org.apache.hadoop.mapreduce.lib.input.FileInputFormat; import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat; import java.io.IOException; import java.util.HashMap; import java.util.Map; public class StockAnalyzer { public static class StockMapper extends Mapper<Object, Text, Text, FloatWritable> { private Text month = new Text(); private FloatWritable volatility = new FloatWritable(); public void map(Object key, Text value, Context context) throws IOException, InterruptedException { String line = value.toString(); String[] fields = line.split(","); if (fields.length == 7 && !fields[0].equals("trade_date")) { String tradeDate = fields[0]; String[] dateParts = tradeDate.split("-"); if (dateParts.length >= 2) { String tradeMonth = dateParts[0] + "." + dateParts[1]; float closePrice = Float.parseFloat(fields[4]); float highPrice = Float.parseFloat(fields[2]); float lowPrice = Float.parseFloat(fields[3]); float volatilityValue = highPrice - lowPrice; volatility.set(volatilityValue); context.write(new Text(tradeMonth), volatility); } } } } public static class StockReducer extends Reducer<Text, FloatWritable, Text, Text> { private Text result = new Text(); public void reduce(Text key, Iterable<FloatWritable> values, Context context) throws IOException, InterruptedException { float totalVolatility = 0; float totalPrice = 0; int count = 0; for (FloatWritable value : values) { totalVolatility += value.get(); count++; } float averagePrice = totalVolatility / count; float volatilityRate = (totalVolatility / averagePrice) * 100; String outputValue = String.format("%.2f-%.2f %.2f%%", averagePrice, totalVolatility, volatilityRate); result.set(outputValue); context.write(key, result); } } public static void main(String[] args) throws Exception { Configuration conf = new Configuration(); Job job = Job.getInstance(conf, "stock analyzer"); job.setJarByClass(StockAnalyzer.class); job.setMapperClass(StockMapper.class); job.setReducerClass(StockReducer.class); job.setOutputKeyClass(Text.class); job.setOutputValueClass(FloatWritable.class); FileInputFormat.addInputPath(job, new Path(args[0])); FileOutputFormat.setOutputPath(job, new Path(args[1])); System.exit(job.waitForCompletion(true) ? 0 : 1); } } ``` pom.xml文件如下: ```xml <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.example</groupId> <artifactId>stock-analyzer</artifactId> <version>1.0-SNAPSHOT</version> <properties> <hadoop.version>3.2.2</hadoop.version> </properties> <dependencies> <dependency> <groupId>org.apache.hadoop</groupId> <artifactId>hadoop-common</artifactId> <version>${hadoop.version}</version> </dependency> <dependency> <groupId>org.apache.hadoop</groupId> <artifactId>hadoop-mapreduce-client-core</artifactId> <version>${hadoop.version}</version> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>3.8.1</version> <configuration> <source>1.8</source> <target>1.8</target> </configuration> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-assembly-plugin</artifactId> <version>3.1.1</version> <configuration> <descriptorRefs> <descriptorRef>jar-with-dependencies</descriptorRef> </descriptorRefs> <archive> <manifest> <mainClass>StockAnalyzer</mainClass> </manifest> </archive> </configuration> <executions> <execution> <phase>package</phase> <goals> <goal>single</goal> </goals> </execution> </executions> </plugin> </plugins> </build> </project> ``` [2024-11-13 12:21:32 | AI写代码神器 | 3687点数解答]
- 现提供某股票在2014-2020的交易信息,数据文件的各个列的说明如下:(数据见附件stocks.csv) trade_date 交易时间 open 开盘价格 high 当日最高价 low 当日最低价 close 收盘价 amount 交易量 统计该股票各个月的波动范围(本月的收盘最低价-本月的收盘最高价),波动率(波动范围/本月收盘价平均价格,保留小数点后2位数字),以及这个月的总成交量输出结果如下: 2019.6 69.64-72.07 3.55% 127897.5 本题可在本地hadoop虚拟环境中验证执行,需提交关键代码的源码截图和执行结果截图,并附带工程源码(提交压缩包) 用java写出代码并给出pom.xml文件(3687点数解答 | 2024-11-13 12:21:32)96
- 现提供某股票在2014-2020的交易信息,数据文件的各个列的说明如下:(数据见附件stocks.csv) trade_date 交易时间 open 开盘价格 high 当日最高价 low 当日最低价 close 收盘价 amount 交易量 统计该股票各个月的波动范围(本月的收盘最低价-本月的收盘最高价),波动率(波动范围/本月收盘价平均价格,保留小数点后2位数字),以及这个月的总成交量输出结果如下: 2019.6 69.64-72.07 3.55% 127897.5 本题可在本地hadoop虚拟环境中验证执行,需提交关键代码的源码截图和执行结果截图,并附带工程源码(提交压缩包) 用java写出代码并给出pom.xml文件(1603点数解答 | 2024-11-13 12:24:18)197
- 现提供某股票在2014-2020的交易信息,数据文件的各个列的说明如下:(数据见附件stocks.csv) trade_date 交易时间 open 开盘价格 high 当日最高价 low 当日最低价 close 收盘价 amount 交易量 统计该股票各个月的波动范围(本月的收盘最低价-本月的收盘最高价),波动率(波动范围/本月收盘价平均价格,保留小数点后2位数字),以及这个月的总成交量输出结果如下: 2019.6 69.64-72.07 3.55% 127897.5 本题可在本地hadoop虚拟环境中验证执行,需提交关键代码的源码截图和执行结果截图,并附带工程源码(提交压缩包) 用java写出代码并给出pom.xml文件(1052点数解答 | 2024-11-13 14:46:13)105
- 300,0,144,1,0,0 300,0,144,0,1,0 300,0,144,0,0,1 300,0,144,1,1,0 300,0,108,0,1,1 184,0,72,1,0,1 184,0,72,0,0,0 184,0,72,0,0,0 184,0,72,0,0,0 184,1,72,1,0,1 184,1,72,0,0,0 184,1,72,0,0,0 184,1,72,0,0,0 184,1,72,0,0,0 184,1,720,0,0,0构建数据文件data.txt(377点数解答 | 2024-12-13 08:02:21)146
- 解释下面代码的含义以及用法 #include <stdio.h> typedef struct { double balance; } bankaccount; //开户 void openaccount(bankaccount *account) { account->balance = 0; printf("开户成功"); } //存款 void deposit(bankaccount *account, double amount) { account->balance += amount; printf("存款 %.2f 成功", amount); } //取款 void withdraw(bankaccount *account, double amount) { if (account->balance >= amount) { account->balance -= amount; printf("取款 %.2f 成功", amount); } else { printf("取款 %.2f,余额不足失败", amount); } } //查询余额 do(298点数解答 | 2024-08-08 15:01:11)188
- 下面代码中的bankaccount *account是什么含义及功能 #include <stdio.h> typedef struct { double balance; } bankaccount; //开户 void openaccount(bankaccount *account) { account->balance = 0; printf("开户成功"); } void deposit(bankaccount *account, double amount) { account->balance += amount; printf("存款 %.2f 成功", amount); } void withdraw(bankaccount *account, double amount) { if (account->balance >= amount) { account->balance -= amount; printf("取款 %.2f 成功", amount); } else { printf("取款 %.2f,余额不足失败", amount); } } d(124点数解答 | 2024-08-08 15:12:48)233
- 下面代码中的bankaccount *account,account->balance += amount;具体解释原理和作用 #include <stdio.h> typedef struct { double balance; } bankaccount; //开户 void openaccount(bankaccount *account) { account->balance = 0; printf("开户成功"); } void deposit(bankaccount *account, double amount) { account->balance += amount; printf("存款 %.2f 成功", amount); } void withdraw(bankaccount *account, double amount) { if (account->balance >= amount) { account->balance -= amount; printf("取款 %.2f 成功", amount); } else { printf("取款(161点数解答 | 2024-08-08 15:18:14)205
- 以下代码使用指针与结构体的作用与好处是什么? #include <stdio.h> typedef struct { double balance; } bankaccount; //开户 void openaccount(bankaccount *account) { account->balance = 0; printf("开户成功"); } void deposit(bankaccount *account, double amount) { account->balance += amount; printf("存款 %.2f 成功", amount); } void withdraw(bankaccount *account, double amount) { if (account->balance >= amount) { account->balance -= amount; printf("取款 %.2f 成功", amount); } else { printf("取款 %.2f,余额不足失败", amount); } } double getbalanc(201点数解答 | 2024-08-08 15:39:09)184
- 实验目的: 1.巩固理解java的面向对象程序设计概念 2.理解java封装的含义 3.理解static, final等关键字的含义及应用实验内容: 定义 book类,给每一本书自动赋上索书号 is sn1, issn2... 声明一个图书类,其数据成员为书名、编号(利用静态变量实现自动编号“issn1” “is sn2”) 书价,册数和静态属性图书的总册数,在构造方法中利用静态变量为对象的编号赋值,在主方法中 定义对象数组,并求出总册数。运行效果如下: 【书名]:java程序书名]:java程序书名]:ava程序 书名j:c语言程序设计书名]:c语言程序设计书名]:null 书名]:nul1 [书名]:nu11 【价格]:35.6 【价格]:35.6 【价格]:35.6 [价格]:42.6 [价格]:42.6 [价格]:8.日 [价格]:8.8 [价格]:8.0 [图书線号]:issn1图书编号]:issn2[图书编号):issn3[图书编号j:issn4图书编号]:issn5图书線号】:issn6[图书線号]:issn7[图书編号]:issn8 [本书的册数]:3 [本书的册数]:(1469点数解答 | 2024-04-02 10:20:41)289
- 解释下面代码含义 typedef struct { double balance; } bankaccount; //开户 void openaccount(bankaccount *account) { account->balance = 0; printf("开户成功"); } //存款 void deposit(bankaccount *account, double amount) { account->balance += amount; printf("\n") ; printf("存款 %.2f 成功", amount); } //取款 void withdraw(bankaccount *account, double amount) { if (account->balance >= amount) { account->balance -= amount; printf("\n") ; printf("取款 %.2f 成功", amount); } else { printf("\n") ; printf("取款 %.2f,余额不足失败", amo(195点数解答 | 2024-08-08 14:53:52)200
- 解释下面每一行代码的含义和作用以及用法 #include <stdio.h> typedef struct { double balance; } bankaccount; //开户 void openaccount(bankaccount *account) { account->balance = 0; printf("开户成功"); } //存款 void deposit(bankaccount *account, double amount) { account->balance += amount; printf("\n") ; printf("存款 %.2f 成功", amount); } //取款 void withdraw(bankaccount *account, double amount) { if (account->balance >= amount) { account->balance -= amount; printf("\n") ; printf("取款 %.2f 成功", amount); } else { printf("\n")(152点数解答 | 2024-08-08 14:58:48)229
- 下面代码中,bankaccount *account和bankaccount account的区别是什么? #include <stdio.h> typedef struct { double balance; } bankaccount; //开户 void openaccount(bankaccount *account) { account->balance = 0; printf("开户成功"); } void deposit(bankaccount *account, double amount) { account->balance += amount; printf("存款 %.2f 成功", amount); } void withdraw(bankaccount *account, double amount) { if (account->balance >= amount) { account->balance -= amount; printf("取款 %.2f 成功", amount); } else { printf("取款 %.2f,余额不足失败", a(174点数解答 | 2024-08-08 15:43:13)198