package com.cn;
import java.util.Scanner;
import java.util.List;
import java.util.ArrayList;
import java.util.Iterator;
class Student{
private String classNumber;
private String name;
private double score;
public Student(String classNumber,String name,double score){
this.classNumber = classNumber;
this.name = name ;
this.score = score;
}
public String getClassNumber(){
return classNumber;
}
public String getName(){
return name;
}
public double getScore(){
return score;
}
}
class Avg{
private double sum = 0;
List<Student> l ;
Iterator<Student> i;
public void TianJia(){
Student s = new Student("01","黎明",90);
Student s1 = new Student("01","黎明1",90);
Student s2 = new Student("01","黎明2",90);
Student s3 = new Student("02","黎明3",80);
Student s4 = new Student("02","黎明4",80);
Student s5 = new Student("02","黎明5",80);
l = new ArrayList<Student>();
i = l.iterator();
l.add(s);
l.add(s1);
l.add(s2);
l.add(s3);
l.add(s4);
l.add(s5);
}
public double getAvg(String number){
if(number.equals("01") || number.equals("02")){
while(i.hasNext()){
Student sTemp = i.next();
if(sTemp.getClassNumber().equals(number)){
sum = sum + sTemp.getScore();
}
}
}
return sum;
}
}
public class ClassAvg{
public static void main(String args[]){
Scanner s = new Scanner(System.in);
String number = s.nextLine();
Avg a = new Avg();
a.TianJia();
double sum = a.getAvg(number);
System.out.println(sum);
}
}
这个东西是求班级平均分的,输入班级编号,就输出班级平均分,编译可以通过,但是执行就出现错误了。蛋疼
import java.util.Scanner;
import java.util.List;
import java.util.ArrayList;
import java.util.Iterator;
class Student{
private String classNumber;
private String name;
private double score;
public Student(String classNumber,String name,double score){
this.classNumber = classNumber;
this.name = name ;
this.score = score;
}
public String getClassNumber(){
return classNumber;
}
public String getName(){
return name;
}
public double getScore(){
return score;
}
}
class Avg{
private double sum = 0;
List<Student> l ;
Iterator<Student> i;
public void TianJia(){
Student s = new Student("01","黎明",90);
Student s1 = new Student("01","黎明1",90);
Student s2 = new Student("01","黎明2",90);
Student s3 = new Student("02","黎明3",80);
Student s4 = new Student("02","黎明4",80);
Student s5 = new Student("02","黎明5",80);
l = new ArrayList<Student>();
i = l.iterator();
l.add(s);
l.add(s1);
l.add(s2);
l.add(s3);
l.add(s4);
l.add(s5);
}
public double getAvg(String number){
if(number.equals("01") || number.equals("02")){
while(i.hasNext()){
Student sTemp = i.next();
if(sTemp.getClassNumber().equals(number)){
sum = sum + sTemp.getScore();
}
}
}
return sum;
}
}
public class ClassAvg{
public static void main(String args[]){
Scanner s = new Scanner(System.in);
String number = s.nextLine();
Avg a = new Avg();
a.TianJia();
double sum = a.getAvg(number);
System.out.println(sum);
}
}
这个东西是求班级平均分的,输入班级编号,就输出班级平均分,编译可以通过,但是执行就出现错误了。蛋疼