Java作业-----查询不及格人数

java作业之查询姓名和不及格人数Java作业-----查询不及格人数_第1张图片

import java.util.Arrays;
import java.util.Scanner;

public class StudentHappy {

	public static void main(String[] args) {
		// TODO 自动生成的方法存根
		Student []stu = new Student[5];
		stu[0] = new Student(2017001,"John smms",80,80,80);
		stu[1] = new Student(2017002,"John fdsa",50,46,75);
		stu[2] = new Student(2017003,"gsa fsaas",79,63,33);
		stu[3] = new Student(2017004,"ffdss fds",88,44,73);
		stu[4] = new Student(2017005,"John iiii",12,23,99);
		
		Scanner sc = new Scanner(System.in);
		
		String cs1 = sc.next();
		
		for(int i =0;i<=stu.length-1;i++) {
			if(stu[i].getName().contains(cs1)) {
				System.out.println("找到了:"+stu[i].getName()+"带有"+cs1+"的名字");
			}else if(i==stu.length-1 && stu[i].getName().contains(cs1)) {
				System.out.println("找不到这个靓仔");
			}
		}
		
		System.out.println("接下来输个名字查询你要找的那个靓仔");
		String la = sc.next();
		for(int i =0;i<=stu.length-1;i++) {
			if(stu[i].getName().contains(la)) {
				System.out.println(stu[i].getName()+"这个靓仔的英语成绩是"+stu[i].getEgl()+"数学成绩是"+stu[i].getHighMath()+"体育成绩是"+stu[i].getGymScore());
			}
		}
		
		//查询输出不及格人数名单		
		String egl[]= new String[5];
		String mth[]= new String[5];
		String ggl[]= new String[5];
		for(int i=0;i<=stu.length-1;i++) {
			if(stu[i].getEgl()<60) {
				egl[i]=stu[i].getName();
			}
			if(stu[i].getHighMath()<60) {
				mth[i]=stu[i].getName();
			}
			if(stu[i].getGymScore()<60) {
				ggl[i]=stu[i].getName();
			}
		}
		System.out.println("英语不及格的人有:"+Arrays.toString(egl));
		System.out.println("数学不及格的人有:"+Arrays.toString(mth));
		System.out.println("体育不及格的人有:"+Arrays.toString(ggl));
	}
	
}

你可能感兴趣的:(个人学习心得)