希望兄弟们帮忙,这是我的期末考试的题目~~~~我的命运就掌握在你们的手里拉!!谢谢
import java.util.*;
class Student{
private String name; //没用上啊!是不是大小写有问题呢?
private String ID; //没用上啊!是不是大小写有问题呢?
private ArrayList<Examination> scores = new ArrayList<Examination>();
public Student(String name,String id){
this.name = name;
this.ID = id;
}
public void SetTestScore(String id,double sc){
Examination ex = new Examination();
ex.ID = id;
ex.score = sc;
this.scores.add(ex);
}
public double GetTestScore(String id){
for(int i=0;i<this.scores.size();i++){
if(scores.get(i).getId().equals(id)){
return scores.get(i).getScore();
}
}
System.out.println("ERROR!!");
return 0;
}
public double average(){
double sum = 0;
for(int i=0;i<scores.size();i++){
sum+=scores.get(i).getScore();
}
return sum/(scores.size()+1);
}
class Examination{
String ID;
double score;
public void setId(String id){
this.ID = id;
}
public void setScore(double sc){
this.score = sc;
}
public String getId(){
return this.ID;
}
public double getScore(){
return this.score;
}
}
}
//编译没有问题了
import java.util.*;
class Student{
private String name;
private String ID;
private ArrayList<Examination> scores = new ArrayList<Examination>();
public Student(String name,String id){
this.name = name;
this.ID = id;
}
public void SetTestScore(String id,double sc){
Examination ex = new Examination();
ex.ID = id;
ex.score = sc;
this.scores.add(ex);
}
public double GetTestScore(String id){
for(int i=0;i<this.scores.size();i++){
if(scores.get(i).getId().equals(id)){
return scores.get(i).getScore();
}
}
System.out.println("ERROR!!");
return 0;
}
public double average(){
double sum = 0;
for(int i=0;i<scores.size();i++){
sum+=scores.get(i).getScore();
}
return sum/(scores.size()+1);
}
class Examination{
String ID;
double score;
public void setId(String id){
this.ID = id;
}
public void setScore(double sc){
this.score = sc;
}
public String getId(){
return this.ID;
}
public double getScore(){
return this.score;
}
public String toString()
{
return "姓名"+name+"ID"+ID;//把其他信息加进去就可以了,现在只有姓名和学号
}
}
}
public class Text
{
public static void main(String args[])
{
Student student=new Student("张三","20号");
System.out.println(student.toString());
}
}