java面向对象之学生通讯录

java面向对象之学生通讯录

定义一个学生类用来存储学生的信息(包括:学号、姓名、英语成绩、高数成绩、体育成绩),在main方法中定义一个数字存储5名学生的信息。
要求:
1.按名字查询并输出成绩
2.查询并输出所有科目不及格的人数及名单

  •  Student类

    package com.student;
    /**
     * 学生类 保存学生的基本信息
     * @author anneli
     *
     */
    public class Student {
    	private int Sno;
    	private String Name;
    	private int English;
    	private int HighNumber;
    	private int Sport;
    	public static int c;
    	
    	
    	
    	public Student() {
    		super();
    		c++;
    		// TODO Auto-generated constructor stub
    	}
    
    	/**
    	 * 构造方法 初始化信息
    	 * @param Sno 学号
    	 * @param Name 姓名
    	 * @param English 英语成绩
    	 * @param HighNumber 高数成绩
    	 * @param Sport 体育成绩
    	 */
    	public Student(int Sno,String Name,int English,int HighNumber,int Sport) {
    		// TODO Auto-generated method stub
    		this.Sno = Sno;
    		this.Name = Name;
    		this.English = English;
    		this.HighNumber = HighNumber;
    		this.Sport = Sport;
    	}
    
    	public int getSno() {
    		return Sno;
    	}
    
    	public void setSno(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 getHighNumber() {
    		return HighNumber;
    	}
    
    	public void setHighNumber(int highNumber) {
    		HighNumber = highNumber;
    	}
    
    	public int getSport() {
    		return Sport;
    	}
    
    	public void setSport(int sport) {
    		Sport = sport;
    	}
    
    	@Override
    	public String toString() {
    		return "Student [Sno=" + Sno + ", Name=" + Name + ", English=" + English + ", HighNumber=" + HighNumber
    				+ ", Sport=" + Sport + "]";
    	}
    	
    }
    
  • StudentList类 

    package com.student;
    import java.util.ArrayList;
    
    /**
     * 学生表 实现学生表的增删查找
     * @author anneli
     *
     */
    public class StudentList {
    	private ArrayList stdList = new ArrayList();
    
    	/**
    	 * 增加学生到学生表
    	 * @param std 学生对象
    	 */
    	public void _add(Student std) {
    		stdList.add(std);
    	}
    	
    	/**
    	 * 按内容查询 模糊查询 输出查询到的学生姓名和成绩
    	 * @param value 查询内容
    	 */
    	public void query(String value) {
    		for (int i = 0; i < stdList.size(); i++) {
    			if (stdList.get(i).getName().contains(value)) {
    				System.out.println("姓名:"+stdList.get(i).getName()+" 英语成绩:"+stdList.get(i).getEnglish()+" 高数成绩:"+stdList.get(i).getHighNumber()+" 体育成绩:"+stdList.get(i).getSport());
    			}
    		}
    		System.out.println();
    	}
    	
    	/**
    	 * 输出学生表的详细信息
    	 */
    	public void print() {
    		for (int i = 0; i < stdList.size(); i++) {
    			System.out.println("学号:"+stdList.get(i).getSno()+" 姓名:"+stdList.get(i).getName()+" 英语成绩:"+stdList.get(i).getEnglish()+" 高数成绩:"+stdList.get(i).getHighNumber()+" 体育成绩:"+stdList.get(i).getSport());
    		}
    		System.out.println();
    	}
    	
    	/**
    	 * 查询不及格的学生并输出
    	 */
    	public void fail() {
    		int people = 0;
    		System.out.print("英语成绩不及格的有:");
    		for (int i = 0; i < stdList.size(); i++) {
    			if (stdList.get(i).getEnglish()<60) {
    				System.out.print(stdList.get(i).getName()+" ");
    				people++;
    			}
    		}
    		System.out.print("总共有"+people+"人\n");
    		
    		people = 0;
    		System.out.print("高数成绩不及格的有:");
    		for (int i = 0; i < stdList.size(); i++) {
    			if (stdList.get(i).getHighNumber()<60) {
    				System.out.print(stdList.get(i).getName()+" ");
    				people++;
    			}
    		}
    		System.out.print("总共有"+people+"人\n");
    		
    		people = 0;
    		System.out.print("体育成绩不及格的有:");
    		for (int i = 0; i < stdList.size(); i++) {
    			if (stdList.get(i).getSport()<60) {
    				System.out.print(stdList.get(i).getName()+" ");
    				people++;
    			}
    		}
    		System.out.print("总共有"+people+"人\n");
    		
    		System.out.println();
    	}
    }
    
    
    
  • Main类

    package com.student;
    
    /**
     * 实现类 测试代码
     * @author anneli
     * @date 2019年9月23日 下午3:04:38 
     *
     */
    public class Main {
    	
    	public Main() {
    	}
    
    	public static void main(String[] args) {
    		Student zhangsan = new Student(20192301, "zhangsan", 88, 55, 88);
    		Student zhangsan1 = new Student(20192302, "wangwu", 66, 66, 55);
    		Student zhangsan2 = new Student(20192303, "xiaoming", 55, 66, 77);
    		Student zhangsan3 = new Student(20192304, "lige", 55, 55, 59);
    		
    		StudentList stdList = new StudentList();
    		stdList._add(zhangsan);
    		stdList._add(zhangsan1);
    		stdList._add(zhangsan2);
    		stdList._add(zhangsan3);
    		
    		Student s1 = new Student();
    		System.out.println(s1.c);
    		Student s2 = new Student();
    		System.out.println(s2.c);
    		
    		stdList.print();
    		stdList.query("ing");
    		stdList.fail();
    	}
    	
    }
    

     

你可能感兴趣的:(java面向对象之学生通讯录)