学生类:学号,名字,成绩;
public class Student {
private int Sno;
private String Name;
private int English;
private int Math;
private int Sports;
public Student(){
}
public Student(Integer Sno,String Name,Integer English,Integer Math,Integer Sports){
this.Sno=Sno;
this.Name=Name;
this.English=English;
this.Math=Math;
this.Sports=Sports;
}
public Number getSno() {
return Sno;
}
public void setSon(int sno) {
Sno = sno;
}
public String getName() {
return Name;
}
public void setName(String name) {
Name = name;
}
public int getEnglish() {
return English;
}
public void setEnglish(int english) {
English = english;
}
public int getMath() {
return Math;
}
public void setMath(int math) {
Math = math;
}
public int getSports() {
return Sports;
}
public void setSports(int sports) {
Sports = sports;
}
}
实现查找不合格学生:
public class StudentManager {
public static void main(String[] args) {
// TODO 自动生成的方法存根
//实例化对象数组
Student[] st=new Student[5];
//创建五个数组
Student st1=new Student(1,"张三",40,55,75);
Student st2=new Student(2,"李四",46,80,75);
Student st3=new Student(3,"王五",50,80,75);
Student st4=new Student(4,"张三风",77,80,46);
Student st5=new Student(5,"张无忌",98,80,39);
st[0]=st1;
st[1]=st2;
st[2]=st3;
st[3]=st4;
st[4]=st5;
//遍历每个人
for(int i=0;i<st.length;i++){
System.out.println("学号:"+st[i].getSno()+",姓名:"+st[i].getName()+",英语成绩:"+st[i].getEnglish()+",数学成绩:"+st[i].getMath()+",体育成绩:"+st[i].getSports());
}
//x,y,z记录人数
int x=0;
int y=0;
int z=0;
//判断英语
System.out.print("英语成绩不合格的有:");
for (int i = 0; i < st.length; i++) {
if(st[i].getEnglish()<60){
x++;
System.out.print(st[i].getName()+",");
}
}
System.out.println("总共有:"+x+"人");
//判断数学
System.out.print("数学成绩不合格的有:");
for (int i = 0; i < st.length; i++) {
if (st[i].getMath()<60) {
y++;
System.out.print(st[i].getName()+",");
}
}
System.out.println("总共有:"+y+"人");
System.out.print("体育成绩不合格的有:");
for (int i = 0; i < st.length; i++) {
if (st[i].getSports()<60) {
z++;
System.out.print(st[i].getName()+",");
}
}
System.out.println("总共有:"+z+"人");
}
}