java问题,求解答

补充以下的程序,如果没有语句,请写完成的语句,语句结束标记要有,若不是完整语句,请填好缺失的内容,符号使用英文。此题符号中英文用错,或缺失符号,空格等,大小写不对,符号用多了,都不给分。

package b;

import java.util.ArrayList;

import java.util.HashSet;

import java.util.Iterator;

import java.util.List;

import java.util.Set;

public class LianXi2 {

public static void main(String[] args) {

【1】 //使用ArrayList保存所有学生的信息,要求指明泛型类为Student,集合对象为list

list.add(new Student("Tom", 18, 100, "class05"));

list.add(new Student("Jerry", 22, 70, "class04"));

list.add(new Student("Owen", 25, 90, "class05"));

list.add(new Student("Jim", 30,80 , "class05"));

list.add(new Student("Steve", 28, 66, "class06"));

list.add(new Student("Kevin", 24, 100, "class04"));

int sage=0;//统计age的和

【2】 //创建学生列表的迭代器对象it,并指明泛型类型为Student

Set<String> bjSet=【3】;//使用HashSet集合对象,保存班级编号,指明泛型为String。

while( 【4】){ //使用迭代器,遍历学生列表。

Student s=【5】;//获取每个学生对象

sage+=s.getAge(); //累加每个学生的成绩

【6】//把学生的班级保存到bjSet集合中

}

【7】//以格式“平均年龄:26”,输出平均成绩

//使用二重循环遍历每个班级的学生,统计出每个班级的学生的成绩,和学生的个数

for(String bj:bjSet){ //使用增强型for遍历每个班级

int score=0;//保存每个班级的成绩

int count=0;//保存每个班级的学生数量

for(Student s:list){ //使用增强型for遍历每个学生

if( 【8】){//判断学生是否在这个班级中

score+=s.getScore(); //累加成绩

【9】 //学生计数

}

}

【10】//以格式“class06---平均成绩---66”格式输出成绩

}

}

}

class Student{

private String name;

private int age;

private int score;

private String classNum;

public String getName() {

return name;

}

public void setName(String name) {

this.name = name;

}

public int getAge() {

return age;

}

public void setAge(int age) {

this.age = age;

}

public int getScore() {

return score;

}

public void setScore(int score) {

this.score = score;

}

public String getClassNum() {

return classNum;

}

public void setClassNum(String classNum) {

this.classNum = classNum;

}

public Student(String name, int age, int score, String classNum) {

super();

this.name = name;

this.age = age;

this.score = score;

this.classNum = classNum;

}

public Student() {

super();

}

}

package b;

import java.util.ArrayList;

import java.util.HashSet;

import java.util.Iterator;

import java.util.List;

import java.util.Set;

public class LianXi2 {

public static void main(String[] args) {
ArrayList<Student> list = new ArrayList(); //使用ArrayList保存所有学生的信息,要求指明泛型类为Student,集合对象为list
list.add(new Student("Tom", 18, 100, "class05"));

list.add(new Student("Jerry", 22, 70, "class04"));

list.add(new Student("Owen", 25, 90, "class05"));

list.add(new Student("Jim", 30,80 , "class05"));

list.add(new Student("Steve", 28, 66, "class06"));

list.add(new Student("Kevin", 24, 100, "class04"));

int sage=0;//统计age的和

Iterator it = list.Iterator(); //创建学生列表的迭代器对象it,并指明泛型类型为Student

Set<String> bjSet= new HashSet();//使用HashSet集合对象,保存班级编号,指明泛型为String。

while( it.hasNext()){ //使用迭代器,遍历学生列表。

Student s= it.next();//获取每个学生对象

sage+=s.getAge(); //累加每个学生的成绩

bjSet.add(s.getClassNum());//把学生的班级保存到bjSet集合中

}

System.out.println("平均年龄:" + sage/list.size());//以格式“平均年龄:26”,输出平均成绩

//使用二重循环遍历每个班级的学生,统计出每个班级的学生的成绩,和学生的个数

for(String bj:bjSet){ //使用增强型for遍历每个班级

int score=0;//保存每个班级的成绩

int count=0;//保存每个班级的学生数量

for(Student s:list){ //使用增强型for遍历每个学生

if( s.getClassNum().equal(bj)){//判断学生是否在这个班级中

score+=s.getScore(); //累加成绩

count+=1; //学生计数

}

}

System.out.println(bj + "---平均成绩---" + score/count);//以格式“class06---平均成绩---66”格式输出成绩

}

}

}

class Student{

private String name;

private int age;

private int score;

private String classNum;

public String getName() {

return name;

}

public void setName(String name) {

this.name = name;

}

public int getAge() {

return age;

}

public void setAge(int age) {

this.age = age;

}

public int getScore() {

return score;

}

public void setScore(int score) {

this.score = score;

}

public String getClassNum() {

return classNum;

}

public void setClassNum(String classNum) {

this.classNum = classNum;

}

public Student(String name, int age, int score, String classNum) {

super();

this.name = name;

this.age = age;

this.score = score;

this.classNum = classNum;

}

public Student() {

super();

}

}
温馨提示:内容为网友见解,仅供参考
无其他回答
相似回答