这是一个关于DR.JAVA编程的一个问题 会的人帮我一下谢谢了

Write a Java program that will read in a data file of student marks information, and calculates and displays the final mark for each student. The program should use TextIO.readUserSelectedFile() to allow the input file to be selected with a standard open file dialog. The line in the file for each student will have the student id number, three assignment marks, one test mark, and one exam mark.

The format of the data in the input file is described in the following:
• the first line in the file contains the number of students represented in the file
• the second line contains the maximum mark for each assignment, test, and exam
• the third line will have the weight of each assignment, test, and exam
• the fourth and subsequent lines contain the id, the assignment marks, the test mark, and the exam mark for each student.

Here is the content of a sample input file:4
10 15 10 40 85
.1 .1 .1 .2 .5
902345 6 12 7 32 68
921147 7 11 8 29 71
993452 7 7 9 24 59
905466 8 13 8 34 74
The output will simply consist of the student number and the computed final mark with one decimal place on a line. Beside the final mark if a student has a mark of at least 90 display three + signs. If the mark is at least 80 but not 90 display two + signs, and if it is at least 70 but not 80 then display one +. In addition to the report of final marks the program must also determine the student with the highest final mark and display the student number of that student along with their mark. The output for the data above would look something like:

Id Nbr Mark902345 77.0 +921147 78.6 +
993452 67.4
905466 85.2 ++
The best student is: 905466 with a mark of 85.2
The actual input file to use with your final program is found here. You can use right click to save the file on your computer.

这是一个我们老师出的作业 本人现在在加拿大上学 刚上大学不久 学的是计算机专业 由于刚上和英语的限制 本人压根看不懂这个题要求是什么 还有要干什么 有没有知道的人能帮我做一下 谢谢了 很急 老师马上就要让交作业了 我问了好多人 都不会 谢谢了
补充一下 最后一段话The actual input file to use with your final program is found here的 found here 是这个网址http://www.cosc.brocku.ca/Offerings/1P02/ass1data.txt

加拿大。。。奥运会都没结束就这么急着开学的么。。。
题目没说输出到这里,我现在都打印在控制台上了。另外,你们老师说的TextIO我不知道是什么,我只是用常规的方法打开文件选择对话框

import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;

import javax.swing.JFileChooser;
import javax.swing.filechooser.FileNameExtensionFilter;

public class Test {

public static void main(String[] args) {
Scanner scanner = null;
try {
File file = readUserSelectedFile();
if (file == null) return;
scanner = new Scanner(file);
} catch (FileNotFoundException e) {
e.printStackTrace();
return;
}

final int examNumber = 5;
int studentsNumber = scanner.nextInt();
int[] fullMark = new int[examNumber];
double[] ratios = new double[examNumber];
getNumbers(fullMark, scanner);
getNumbers(ratios, scanner);
for (int i = 0; i < examNumber; ++i) {
ratios[i] = ratios[i] * 1000 / fullMark[i];
}

int id, maxScoreID = -1, realScore, maxScore = -1;
int[] scores = new int[examNumber];
double score;

processOutputHeader();
for (int i = 0; i < studentsNumber; ++i) {
id = scanner.nextInt();
getNumbers(scores, scanner);
score = 0;
for (int j = 0; j < examNumber; ++j)
score += ratios[j] * scores[j];

realScore = processScore(id, score);

if (realScore > maxScore) {
maxScore = realScore;
maxScoreID = id;
}

}

System.out.printf("The best student is: %d with a mark of %s\n",
maxScoreID, parseScore(maxScore));

}

static String parseScore(int score) {
return (score / 10) + "." + (score % 10);
}

static void processOutputHeader() {
System.out.println("ID Nbr\tMark");
}

/*
* Since we need only one decimal, the full mark is considered to be 1000
* instead of 100 to eliminate the inaccuracy of floating point arithmetic.
* Otherwise, we might get a score of, say, 79.99. This score, through
* comparison with decimal literal 80, would be considered to be less than
* 80 and thus gets only one "+". However, it might be rounded to 80.0
* when displayed, which causes inconsistency.
*/
static int processScore(int id, double score) {
System.out.printf("%d\t", id);
int realScore = (int) Math.round(score);
int integer = realScore / 10, decimal = realScore % 10;
System.out.printf("%d.%d", integer, decimal);

if (integer >= 90) {
System.out.println("+++");
} else if (integer >= 80) {
System.out.println("++");
} else if (integer >= 70) {
System.out.println("+");
} else {
System.out.println();
}
return realScore;
}

static void getNumbers(int[] array, Scanner scanner) {
for (int i = 0; i < array.length; ++i)
array[i] = scanner.nextInt();
}

static void getNumbers(double[] array, Scanner scanner) {
for (int i = 0; i < array.length; ++i)
array[i] = scanner.nextDouble();
}

static File readUserSelectedFile() {
JFileChooser chooser = new JFileChooser();
chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
chooser.setFileFilter(new FileNameExtensionFilter(null, "txt"));
chooser.setMultiSelectionEnabled(false);

chooser.showOpenDialog(null);
return chooser.getSelectedFile();
}

}
温馨提示:答案为网友推荐,仅供参考
第1个回答  2010-02-25
你学计算机的话还是多动手吧!
引入下面这个包读取TEXT文档:
import java.util.TreeSet;
估计处理这些数字要用到正则表达式,
把数据用数组分别储存起来,
楼上这位已经给出了数据的计算方法了。
题目大意是:
编写一个JAVA程序:从一个数据文档中读取每个学生的得分信息,并且计算出最终成绩。该程序应该使用TextIO.readUserSelectedFile()方法从标准对话框中选择录入文件。文档中每一行包含一名学生的三项作业得分,一项测试得分,一项考试得分。

输入文件的格式如下:
文档的第一行包含一个表示该学生的代号;
第二行包含每项的满分标准;
第三行包含每项成绩的比重权值;
第四行及后面的所有行表示学生的各项对应成绩。
举例如下:
Here is the content of a sample input file:4
10 15 10 40 85
.1 .1 .1 .2 .5
902345 6 12 7 32 68
921147 7 11 8 29 71
993452 7 7 9 24 59
905466 8 13 8 34 74

在这个表中成绩计算方法是:
915466 (8/10*0.1+13/15*0.1+8/10*0.1+34/40*0.2+74/85*0.5)*100=85.2
输入要求计算出每个学生的最终成绩。90分以上的后面显示“+++”,80-90的显示“++”,70-80的显示“+”。程序末尾要说明最高成绩的学生的代号及其分值。
例如:
Id Nbr Mark
902345 77.0 +
921147 78.6 +
993452 67.4
905466 85.2 ++

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网