【发布时间】:2017-04-12 23:58:21
【问题描述】:
我对 Java 非常陌生,我的老师给了我们这个任务,让我们可以在网上查找如何让代码工作的想法。我感到很迷茫,因为我只使用过一次数组和一次双数组。我真的可以使用一些帮助和解释来说明如何让这个程序运行。
到目前为止,我的老师已经教我如何划分学生和成绩,但他没有教我如何打印成绩。另外,当您有一个双数组时,如何仅使用每个学生的行而不是列来计算平均值?
评分模式:在一个单独的函数中,您将实现一个评分模式。写一个 从用户提供的文件中读取学生姓名和考试成绩的程序。 文件中的前两个值将代表学生人数,然后是测试人数。 然后程序应计算每个学生的平均考试成绩并分配适当的 等级(A、B、C、D、E 或 F)以及每个测试的平均值。您的程序必须执行以下操作 职能。 a) 一个void函数calculateAverage,用于确定每个学生的平均考试成绩。
这是txt文件:
汤姆 91 67 84 50 69
苏西 74 78 58 62 64
彼得 55 95 81 77 61
保罗 91 95 92 77 86
黛安 91 54 52 53 92
艾米丽 82 71 66 68 95
娜塔莉 97 76 71 88 69
本 62 67 99 85 94
马克 53 61 72 83 73
安娜 64 91 61 53 68
这是我目前所拥有的:
public class Grades {
private static final String FILENAME2 = "/Users/Jarvis/Documents/Students.txt";
public static void main(String[] args) {
BufferedReader br = null;
FileReader fr = null;
try {
fr = new FileReader(FILENAME2);
br = new BufferedReader(fr);
String students [] = new String[10];
int [][] grades = new int [10][5];
String[] words;
String sCurrentLine;
int counter=0;
br = new BufferedReader(new FileReader(FILENAME2));
while ((sCurrentLine = br.readLine()) != null) {
words = sCurrentLine.split(" ");
students[counter]=words[0];
System.out.print(students[0]+ " ");
for (int i=1; i < words.length; i++){
grades[counter][i-1]=Integer.parseInt(words[i]);
} //end of outer for loop
System.out.println();
} // end of while loop
} catch (IOException e) {
e.printStackTrace();
}
}//end of main
public static void calculateAverage (int grade [][]){
int temp;
int sum;
} // end of calculateAverage()
【问题讨论】:
-
计数器应该是 counter++。
标签: java multidimensional-array