我目前正在使用此选项3:下载统计信息来处理C语言
如果用户选择此选项,程序将使用以下数据创建统计文件:
a. Power output sorted from lowest to highest b. Day with highest output c. Total by month d. Average power output for all the data
统计信息文件将与输入文件具有相同的名称,但附加了_stats.txt。例如,如果输入文件名为data.txt,则stats文件将命名为data_stats.txt。
我的数据文件包含
January 10 2018 236.9January 11 2018 267.6January 12 2018 278.1January 13 2018 246.9January 14 2018 262.3January 15 2018 288.6February 2 2018 199.7February 3 2018 134.6February 4 2018 200.8February 5 2018 198.2March 9 2018 169.7March 10 2018 168.3March 11 2018 179.4
当我运行C时,我的总功率是288.6,我如何获得每个月的总和?
public static void createStatsFile(ArrayList<Entry> uploadResults) { /////////////// ///////A/////// /////////////// try { PrintWriter writer = new PrintWriter("data_stat.txt", "UTF-8"); ArrayList<Entry> lowestToHighest = bubbleSort(uploadResults); for(Entry entry : lowestToHighest) { writer.print( "Month: " + entry.getMonth() + " Day: " + entry.getDay() + " Year: " + entry.getYear() + " Power Output: " + entry.getPowerOutput()); writer.print("\n"); entry.print(); }
我的课:
public class Entry { //declaring variables private String month; private String day; private String year; private float powerOutput; private String file; private int[] MonthList; String inputFile = file; //Constructors public Entry() { } public Entry(String m, String d, String y, float p) { month = m; day = d; year = y; powerOutput = p; } //creating print to call ArrayList in main public void print() { System.out.println("Month: " + month + " Day: " + day + " Year: " + year + " Power Output: " + powerOutput); } public static void getFile() { } public String getMonth() { return month; }
慕村9548890
繁星点点滴滴
相关分类