Phase 1 – Numbers
Prior to starting this phase, make sure you download numTestData.txt and numbers.txt from the Moodle class website. numTestData.txt will be the input file you use to get your program working. numbers.txt contains a larger data set and should be used for input only after your program works perfectly.
Write a console program (NO GUI) called NumberSorter which does the following:
1. Open and read the first line of the input file.
2. Create an integer array named numberArray with size to match the first line of the file. So if the first line of the file contains 500, the array will have 500 “slots.”
3. Read the remaining lines of the input file, parsing them as numbers, and assigning them to slots in numberArray.
4. Write a method named sort, which takes numberArray as a parameter and sorts the array from low to high.
5. Once numberArray has been sorted, use a simple loop to compute the average of the numbers in the array (not including the count).
6. When sorting is completed and the average has been calculated, open a file named dataout.txt and write the following information to it:
a. The count (number of “slots” in numberArray).
b. The sorted list of numbers in numberArray (one per line).
c. The calculated average of the numbers in the array. 
Once are certain that your NumberSorter.java program works perfectly, change the name of the input file to numbers.txt and run the program. This should produce an output file containing the number 100 on the first line followed by the sorted list of numbers from 1 to 100, and then the average on the last line.
 
陆续还会有题目发布,这里面涵盖了数组,流的知识。关键是你还要读的懂英语哦。亲!
大家都来试试吧!!

解决方案 »

  1.   

    首先,搞成中文,这个不应该成为编程的障碍阶段1——数字
    在开始第一阶段之前,去报你已经从Moodle class站点下载了numTestData.txt和numbers.txt这两个文件。numTestData.txt将作为你调试程序时的输入文件。numbers.txt文件是正式的数据文件,包含了大量的数据,当你的程序调试完全成功后再使用这个文件。
    编写一个基于命令行的程序(不是GUI程序),该程序的名字叫做:NumberSorter,程序需要满足下列的要求:
    1. 打开并读入输入文件的第一行
    2. 创建一个整形数组,命名为numberArray,其大小与输入文件的第一行包含的数字相当。如果文件的第一行是500,那么数组的的大小就是500.
    3. 读入输入文件余下的行,并将其转换为数字类型,然后存入到数组中对应的位置。
    4. 创建一个方法,叫做sort. 这个方法以numberArray为参数,并能够将数组中的数字从小到大排序。
    5. 一旦numberArray排序完成,使用简单的循环语句计算数组中所有数字所对应的平均值(不包括个数)
    6. 当排序完成,平均数计算也完成,打开一个叫做dataout.txt的文件,将下列信息写入到该文件:
       a. 个数(也就是numberArray数组的大小)
       b. 排序后的numberArray中的数字序列(每行一个数)
       c. 计算出来的数组中所有数字的平均值
    当你的NumberSorter.java程序能够正常运行以后,将输入文件名字改为numbers.txt, 并运行程序,程序运行的正常结果应该产生一个输出文件,该文件的第一行应该是数字100,其后是经过排序的数字,从1到100,最后一行应该是这些数字的平均值。其次,这个没什么困难的,最基本的文件读取和数组排序
      

  2.   

    这个题的关键在这里:numbers.txt contains a larger data set
    而numTestData.txt中的数据很有限这个问题并不像看上去那么简单,因为大多数人在用测试数据去写程序的时候相信都会使用内排序,
    而实际数据非常大,如有几百M,几G的数据,这也是这个题没有限制的地方,用内排序不能解决问题,需要使用外排序,
    问题就在于外排序,很多人都不会。