package com.sf._02_hashmap.demo2;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class ScoreManager {
    // 存储学生成绩
    private static Map<Student,Double> studentsMap = new HashMap<>();
    // 存储学生集合信息  某一个班级的所有学生
    static List<Student> oneStudents = new ArrayList<>();
    /**
     * 添加成绩
     * 把信息保存map  ,map  key-value
     * key - Student  value_ score
     */
    public static void addScore(Student student , Double score){
        // 判断录入学生是否是这个班级的
        if(!oneStudents.contains(student)){
            System.out.println("学生不是这个班级的!");
            return;
        }
        studentsMap.put(student,score);
    }

    /**
     * 批量添加成绩
     * addAll(Map map)
     */
    public static void addAllScore(HashMap<Student,Double> map){
        studentsMap.putAll(map);
    }

    /**
     * 修改成绩
     * put(key , value)
     * student  double
     */
    public static void changeScore(Student student,Double score){
        studentsMap.put(student,score);
    }

    /**
     * 删除成绩
     * 跟key 进行删除
     * key student
     */
    public static void removeScore(Student student){
        studentsMap.remove(student);
    }

    /**
     * 查询成绩
     */
    public static void queryScore(){
        for (Map.Entry<Student, Double> studentDoubleEntry : studentsMap.entrySet()) {
            System.out.println("学生姓名:"+studentDoubleEntry.getKey().getName() +"成绩为:"+ studentDoubleEntry.getValue());
        }
    }

    /**
     * 查看及格人数
     */
    public static void queryScorePass(){
        int count = 0;
        for (Double score : studentsMap.values()) {
            if(score >= 60){
                count++;
            }
        }
        System.out.println("及格人数:"+ count);
    }

    public static void main(String[] args) {
        Student student = new Student(1L,"zhangsan");
        Student student1 = new Student(2L,"lisi");

        // 这两个学生添加一班的集合中
        oneStudents.add(student);
        oneStudents.add(student1);

//        Student student2 = new Student(3L,"wangwu");
//        addScore(student1,80.0);
//        addScore(student,90.0);
//
//        System.out.println(studentsMap);
        HashMap<Student,Double> map = new HashMap<>();
        map.put(student,90.0);
        map.put(student1,80.0);
        addAllScore(map);

//        changeScore(student,100.0);
        queryScore();
        queryScorePass();


    }
}
