public class Student {
private String stName;
private int stNum;
private double stEng;
private double stMath;
private double stPh;
public Student(){
}
public Student(String stName,int stNum,double stEng,double stMath,double stPh){
//super();
this.stName=stName;
this.stNum=stNum;
this.stEng=stEng;
this.stMath=stMath;
this.stPh=stPh;
}
public String getStName() {
return stName;
}
public String toString(){
return "Num:"+stNum+","+"Name:"+stName+","+"English:"+stEng+","+"Math:"+stMath+","+"Physical:"+stPh+" ";
}
public void setStName(String stName) {
this.stName = stName;
}
public int getStNum() {
return stNum;
}
public void setStNum(int stNum) {
this.stNum = stNum;
}
public double getStEng() {
return stEng;
}
public void setStEng(double stEng) {
this.stEng = stEng;
}
public double getStMath() {
return stMath;
}
public void setStMath(double stMath) {
this.stMath = stMath;
}
public double getStPh() {
return stPh;
}
public void setStPh(double stPh) {
this.stPh = stPh;
}
}
public class StudentManage extends Student{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
Student[] stu=new Student[6];
stu[0]=new Student("张三", 1, 65, 56, 89);
stu[1]=new Student("李四", 2, 54, 84, 12);
stu[2]=new Student("王五", 3, 35, 64, 45);
stu[3]=new Student("张六", 4, 45, 14, 65);
stu[4]=new Student("李七", 5, 78, 64, 28);
stu[5]=new Student("王八", 6, 46, 84, 79);
System.out.print("请输入要查询的学生姓名:");
String name = sc.next();
boolean find = false;
for (Student student : stu) {
if (student.getStName().contains(name)) {
System.out.println(student);
find = true;
}
}
if (!find) {
System.out.println("没有查询到该学生");
}
List<Student> EnglishNoPass = new ArrayList<>();
List<Student> MathNoPass = new ArrayList<>();
List<Student> PhysicalNoPass = new ArrayList<>();
for (Student student : stu) {
if (student.getStEng() < 60) {
EnglishNoPass.add(student);
}
if (student.getStMath() < 60) {
MathNoPass.add(student);
}
if (student.getStPh() < 60) {
PhysicalNoPass.add(student);
}
}
System.out.println("科目不及格的学生:");
System.out.print("英语成绩不及格:");
Student student;
for (int i = 0; i < EnglishNoPass.size(); i++) {
student = EnglishNoPass.get(i);
if (i != EnglishNoPass.size() - 1) {
System.out.print(student.getStName() + "、");
} else {
System.out.println(student.getStName() + ",总共有" + EnglishNoPass.size() + "人");
}
}
System.out.print("数学成绩不及格:");
for (int i = 0; i < MathNoPass.size(); i++) {
student = MathNoPass.get(i);
if (i != MathNoPass.size() - 1) {
System.out.print(student.getStName() + "、");
} else {
System.out.println(student.getStName() + ",总共有" + MathNoPass.size() + "人");
}
}
System.out.print("体育成绩不及格:");
for (int i = 0; i < PhysicalNoPass.size(); i++) {
student = PhysicalNoPass.get(i);
if (i != PhysicalNoPass.size() - 1) {
System.out.print(student.getStName() + "、");
} else {
System.out.println(student.getStName() + ",总共有" + PhysicalNoPass.size() + "人");
}
}
}
}
转载自原文链接, 如需删除请联系管理员。
原文链接:小型学生查询系统,转载请注明来源!