日期:2014-05-20  浏览次数:20580 次

java的,这题怎么做,求解
创建一个二维对象数组,数组中的每个元素为一个学生类的实例,学生类的UML图为:其中,属性score数组的内容使用random,分数的处理可定义。
Student
-ID:String
-name:String
-score[MAXLENGTH]:float
+Student(ID:String,name:String)
+getID():String
+getName():String
+setID(String id):void
+setName(String name):void



------解决方案--------------------
ArrayList<Students> students_1d;
ArrayList<ArrayList> stutends_2d = new ArrayList<ArrayList>();

Student s1,s2,s3;
students_1d = new ArrayList<Students>();
students_1d.add(s1);
students_1d.add(s2);
students_1d.add(s3);
students_2d.add(students_1d);

Student s4,s5;
students_1d = new ArrayList<Students>();
students_1d.add(s4);
students_1d.add(s5);
students_2d.add(students_1d);


------解决方案--------------------
Java code
Student[][] students=new Student[10][10];
for(int i=0;i<10;i++){
       for(int j=0;j<10;j++){
                students[i][j]=new Student(id,name);//id和name值自己写
                students[i][j].score=new Random().nextFloat()*100 ;//...score没有set?那我就当Public用了吧
        }
}

------解决方案--------------------
class Student
{
String id;
String name;
float score;
get/set
}