1.学生的javabean
public class Student {
private int sno;
String name;
private int englishscore;
private int mathscore;
private int pescore;
Student(int sno,String name,int englishscore,int mathscore,int pescore){
this.sno=sno;
this.name=name;
this.englishscore=englishscore;
this.mathscore=mathscore;
this.pescore=pescore;
}
public int getSno() {
return sno;
}
public void setSno(int sno) {
this.sno = sno;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getEnglishscore() {
return englishscore;
}
public void setEnglishscore(int englishscore) {
this.englishscore = englishscore;
}
public int getMathscore() {
return mathscore;
}
public void setMathscore(int mathscore) {
this.mathscore = mathscore;
}
public int getPescore() {
return pescore;
}
public void setPescore(int pescore) {
this.pescore = pescore;
}
public String toString(){
return "学号:"+this.sno+",姓名:"+this.name+",英语成绩:"+englishscore+",高数成绩:"+this.mathscore+",体育成绩:"+this.mathscore;
}
}
2.编写查询,对比的方法
import java.util.Scanner;
public class cx {
private static Student[]student = null;
public static void search(String string) {
}
public static void main(String[] args) {
System.out.println("请输入要查找的学生名字:");
Scanner scanner=new Scanner(System.in);
String ren=scanner.next();
student=new Student[5];
student[0]=new Student(01,"韦一",48,79,80);
student[1]=new Student(02,"韦二",54,84,35);
student[2]=new Student(03,"张三",94,16,57);
student[3]=new Student(04,"李四",84,18,87);
student[4]=new Student(05,"王五",27,68,33);
int count = 0;
int counts=0;
int coun =0;
if (ren.contains("韦")) {
System.out.println(student[0]);
System.out.println(student[1]);
}
if (ren.contains("张")) {
System.out.println(student[2]);
}
if (ren.contains("李")) {
System.out.println(student[3]);
}
if (ren.contains("王")) {
System.out.println(student[4]);
}
System.out.print("英语成绩不及格的人:");
for(int i=0;i<student.length;i++){
if(student[i].getEnglishscore()<=60){
System.out.print(student[i].name+",");
count=count+1;
}
}
System.out.println("总共有 "+count+"人。");
System.out.print("高数成绩不及格的人:");
for(int i=0;i<student.length;i++){
if(student[i].getMathscore()<=60){
System.out.print(student[i].name+",");
counts=counts+1;
}
}
System.out.println("总共有 "+counts+"人。");
System.out.print("体育成绩不及格的人:");
for(int i=0;i<student.length;i++){
if(student[i].getPescore()<=60){
System.out.print(student[i].name+",");
coun=coun+1;
}
}
System.out.println("总共有 "+coun+"人。");
}
}