我對編程還很陌生,需要在正確的方向上微調一下。該程序從文件中讀取並計算最高分,平均分和刪除重複項等。然後將其項目等級添加到最後,項目等級「N」被忽略,其他等級被追加到結尾。我將在帖子末尾添加文本文件。追加項目檔次
說明:
XcelStudent
XcelStudent擴展學生。一個XcelStudent有一個String實例 變量projectGrade,即得到由XcelStudent構造方法設置: 公共XcelStudent(字符串名稱,詮釋ID,詮釋totalGrades,字符串 projectGrade)此構造函數應該調用父類的構造函數 實例學生實例變量。
重寫computeScore()方法。它應該調用學生 computeScore方法獲得初始等級,然後爲該項目添加適當的點數:1表示「C」,2表示 「B」,4表示「A」 。
toString()方法應該從Student調用toString方法到 得到一個初始String,然後在它後面追加「project:」+ projectGrade到 它。
我相信這是完整的第一部分,我有它檢測四個等級,但我不知道如何將它們追加到最後。
public class XcelStudent extends Student{
public String projectGrade;
public XcelStudent(String name, int id, int totalGrades, String norX) {
super(name, id, totalGrades);
int points;
if(norX.equals("C")){
projectGrade = "C";
//points = 1;
System.out.println(" project:" + projectGrade);
}
if(norX.equals("B")){
projectGrade = "B";
//points = 2;
System.out.println(" project:" + projectGrade);
}
if(norX.equals("A")){
projectGrade = "A";
//points = 4;
System.out.println(" project:" + projectGrade);
}
}
public static void main(String[] args) {
}
}
當前的toString和computeScore在我Student.java
public String toString() {
String res = name + "\t" + id + " ";
for (int i=0; i < totalGrades; i++) {
res += " " + grades[i];
}
res += "\tscore: " + new DecimalFormat("0.00").format(computeScore());
return res;
}
@Override
public double computeScore() {
double total = 0;
if (numGrades == 0) {
return total;
}
if (numGrades > grades.length) {
numGrades = grades.length;
}
for (int i = 0; i < numGrades; i++) {
total += grades[i];
}
if (total > topscore){
topscore = total;
}
avgscore += total;
return total/grades.length;
}
電流輸出:(我知道它不是排序)
Course cs161: 5 grades
project:C
project:A
project:A
project:B
Top Score: 90.0
Avg Score: 76.16
Course: cs161
Adam 2143 85 95 85 75 65 score: 81.00
John 1243 60 70 80 55 55 score: 64.00
Mick 1324 70 60 70 80 90 score: 74.00
Ellen 2341 90 95 88 77 66 score: 83.20
Jim 1234 50 40 50 60 70 score: 54.00
Lena 1423 99 50 90 90 85 score: 82.80
Leila 1432 60 70 60 70 60 score: 64.00
Mike 1342 60 70 80 90 99 score: 79.80
Ada 2134 90 90 90 90 90 score: 90.00
Helen 2314 89 79 99 89 88 score: 88.80
所需的輸出:
Course cs161: 5 grades
Top Score: 92.0
Avg Score: 77.26
Course: cs161
Jim 1234 50 40 50 60 70 score: 54.00
John 1243 60 70 80 55 55 score: 64.00
Mick 1324 70 60 70 80 90 score: 75.00 project: C
Mike 1342 60 70 80 90 99 score: 79.80
Lena 1423 99 50 90 90 85 score: 86.80 project: A
Leila 1432 60 70 60 70 60 score: 64.00
Ada 2134 90 90 90 90 90 score: 92.00 project: B
Adam 2143 85 95 85 75 65 score: 81.00
Helen 2314 89 79 99 89 88 score: 88.80
Ellen 2341 90 95 88 77 66 score: 87.20 project: A
文件:
Adam 2143 N 85 95 85 75 65
adam2 2143 N 0 0 0 0 0
John 1243 N 60 70 80 55 55
John2 1243 N 0 0 0 0 0
Mick 1324 C 70 60 70 80 90
Ellen 2341 A 90 95 88 77 66
Jim 1234 N 50 40 50 60 70
Lena 1423 A 99 50 90 90 85
Leila 1432 N 60 70 60 70 60
Mike 1342 N 60 70 80 90 99
Ada 2134 B 90 90 90 90 90
Helen 2314 N 89 79 99 89 88
感謝您的幫助!
謝謝!我做了改變,它的工作! – Damoclyes 2014-12-11 04:55:48