我仍然是一个漂亮的新手程序员,所以请尽可能描述。我有问题让我所有的代码为我的任务工作。该作业为我提供了四个完全不需要更改的文件(StudentIf.java StudentCollectionIf.java StudentLLNode.java和StudentRecords.java)和一个测试文本文件,其中包含一个ID和五个等级的名称列表。学生数据库与链接列表
链接赋值指令: https://www.cs.colostate.edu/~cs161/Fall14/more_assignments/P5/P5.html
,我已经修改了两个文件是Student.java和StudentLL.java 此外,在我的运行配置论点我有“cs161 5” 我知道它的很多但任何帮助都会很棒。
我目前得到这个输出(最高分,平均分数还没有实现)
Course cs161: 5 grades
Top Score: 10.0
Avg Score: 10.0
Course: null
null 0 score: 81.00
什么应该被制造
Course cs161: 5 grades
Top Score: 90.0
Ave Score: 76.16
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: 74.00
Mike 1342 60 70 80 90 99 score: 79.80
Lena 1423 99 50 90 90 85 score: 82.80
Leila 1432 60 70 60 70 60 score: 64.00
Ada 2134 90 90 90 90 90 score: 90.00
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: 83.20
我对Student.java和StudentLL.java代码
import java.text.DecimalFormat;
import java.util.Arrays;
public class Student implements StudentIF{
private String name;
private int id;
private int[] grades;
private int numGrades;
private int totalGrades;
// The constructor
// initializes the instance variables
// name, id, grades = new int[totalGrades], and numGrades = 0;
public Student (String name, int id, int totalGrades){
name = this.getName();
id = this.getId();
grades = new int[totalGrades];
numGrades= 0;
//System.out.println(name+" "+id+" "+grades[0]+" "+grades[1]+" "+grades[2]+" "+grades[3]+" "+grades[4]+" "+" "+totalGrades);
}
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 int compareTo(StudentIF arg0) {
if (arg0 == null) {
return 1;
}
if (this.id > arg0.getId())
return 1;
else if (this.id < arg0.getId())
return -1;
else
return 0;
}
@Override
public String getName() {
return name;
}
@Override
public int getId() {
return id;
}
@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];
}
return total/numGrades;
//return 0;
}
@Override
public boolean addGrade(int newGrade) {
if(numGrades<grades.length){
grades[numGrades] = newGrade;
numGrades++;
// System.out.println(grades[0]+" "+grades[1]+" "+grades[2]+" "+grades[3]+" "+grades[4]);
return true;
}
return false;
}
@Override
public boolean equals(StudentIF other) {
if (other.getId() == this.getId()) {
return true;
}
return false;
}
}
========
public class StudentLL implements StudentCollectionIF{
private String course;
private StudentLLNode head;
private int size;
private boolean debug; // you can set debug in main
// the client code provides the course name
public StudentLL(String course){
course = this.course;
}
public String toString(){
String res = "Course: " + course + "\n";
for(StudentLLNode curr = head; curr !=null; curr=curr.getNext()){
StudentIF nS = curr.getStd();
res = res + nS + "\n";
}
return res;
}
@Override
public boolean insort(StudentIF s) {
StudentLLNode curr = head;
if (s == null) {
return false;
}
if (head == null) {
StudentLLNode student = new StudentLLNode(s);
head = student;
size++;
//System.out.println("working");
return true;
} else {
if (curr.getStd().compareTo(s) == 0) {
//System.out.println("working");
return false;
}
while (curr.getNext() != null) {
if(s.compareTo(curr.getStd()) == 1){
//c
}
curr = curr.getNext();
}
//c
StudentLLNode student1 = new StudentLLNode(s);
curr.setNext(student1);
size++;
return true;
}
}
@Override
public boolean remove(StudentIF s) {
StudentLLNode current = head;
if(s == null){
return false;
}
if(s.getId() == (head.getStd().getId())){
//StudentLLNode top = head;
head = head.getNext();
size--;
return true;
}
else{
StudentLLNode previous, next;
previous = current;
current = current.getNext();
while(current != null){
next = current.getNext();
if(s.getId() == (current.getStd().getId())){
previous.setNext(next); //doesn't matter if next is null or not
size--;
return true;
}
previous = current;
current = next;
}
}
return false;
}
@Override
public int size() {
// TODO Auto-generated method stub
return size;
}
@Override
public double classAvg() {
//double total = 0.0;
//for (int i=0; i<this.size(); i++) {
// total += grades[i];
//}
//return total/grades.length;
return 10;
}
@Override
public double classTopScore() {
return 10;
}
}
这是一吨的帮助,谢谢!它打印出我需要的所有东西,没有重复的东西。但它不是通过ID排序的,对该部分有任何建议? – Damoclyes 2014-11-22 01:17:12