/*
编写一个程序的模拟班级学生的成绩库, 包含多项成绩,英语,数学,Java.
实现如下功能:
1.可以修改某个学生的某项分数.
2.可以打印全班同学成绩
要求使用集合来完成.*/
public class Test1 {
public static void main(String[] args) {
ArrayList<Student> a = new ArrayList<Student>();
Student c1= new Student("张三",70,70,70);
Student c2= new Student("李四",80,80,80);
Student c3= new Student("王五",90,90,90);
a.add(c1);
a.add(c2);
a.add(c3);
dy(a);
xg(a);
dy(a);
}
public static void xg(ArrayList<Student> a){
System.out.println("请输入您要修改的学生的姓名");
Scanner sc =new Scanner(System.in);
String name= sc.next();
for (int i=0;i<a.size();i++){
Student c = a.get(i);
if(c.getName().equals(name)){
System.out.println("请输入该同学最新英语成绩");
c.setYingyu(new Scanner(System.in).nextDouble());
System.out.println("请输入该同学最新数学成绩");
c.setShuxu(new Scanner(System.in).nextDouble());
System.out.println("请输入该同学最新java成绩");
c.setJava(new Scanner(System.in).nextDouble());
System.out.println("修改成功");
return;
}
}
System.out.println("无此学生");
}
public static void dy(ArrayList<Student> a){
for (Student i: a) {
System.out.println(i.getName()+" "+i.getShuxu()+" "+i.getYingyu()+" "+i.getJava());
}
}
}
|
|