새소식

인기 검색어

비트교육_단기과정

Set<E> 성적관리

  • -

학생정보관리.class

package project_0707;
 
import java.util.*;
 
public class InformationManagement {
    public void overlapCheck(Set<StudentInfo> arr, String std_id) throws Exception {// 학번 중복체크
 
        for (StudentInfo info : arr) {
            if (std_id.equals(info.getStd_id())) {// 리스트에 해당 학번이 존재할경우
                throw new Exception();
            }
        }
    }
 
    public void emptyStdIdCheck(Set<StudentInfo> arr, String std_id) throws Exception {// 정보내 해당 학번의 데이터가 없을 시
 
        for (StudentInfo info : arr) {
            if (!std_id.equals(info.getStd_id())) {// 리스트에 해당 학번이 존재할경우
                throw new Exception();
            }
        }
    }
 
    public void insertInfo(TreeSet<StudentInfo> arr, Scanner sc) throws Exception {// 학생정보 입력
        System.out.println("======학생정보입력======");
        System.out.print("학번을 입력하시오 : ");
        String std_id = sc.next();
        overlapCheck(arr, std_id);// 사번 중복입력 메서드 호출 , 중복값이 존재하지않으면 true
        System.out.print("학과를 입력하시오 : ");
        String std_department = sc.next();
        System.out.print("이름을 입력하시오 : ");
        String name = sc.next();
        System.out.print("국어 점수를 입력하시오 : ");
        int kor = sc.nextInt();
        System.out.print("영어 점수를 입력하시오 : ");
        int eng = sc.nextInt();
        System.out.print("수학 점수를 입력하시오 : ");
        int mat = sc.nextInt();
        StudentInfo studentInfo = new StudentInfo(std_id, std_department, name, kor, eng, mat);
        arr.add(studentInfo);
    }
 
    public void dispALLInfo(Set<StudentInfo> arr) {// 리스트 전체출력
        if (!arr.isEmpty()) {
            System.out.println("======학생 정보 출력======");
            for (StudentInfo info : arr) {
                System.out.println("학번 : " + info.getStd_id() + "  학과 : " + info.getStd_department() + "  이름 : "
                        + info.getName() + "  국어 : " + info.getKor().getSubject() + "  영어 : "
                        + info.getEng().getSubject() + "  수학 : " + info.getMat().getSubject() + "  총점 : "
                        + info.getTotal() + "  평균 : " + info.getAvg());
            }
        } else
            System.out.println("출력할 데이터가 존재하지않습니다");
 
    }
 
    public void dispInfo(StudentInfo info) {
        if (!(info == null)) {
            System.out.println("학번 : " + info.getStd_id() + "  학과 : " + info.getStd_department() + "  이름 : "
                    + info.getName() + "  국어 : " + info.getKor().getSubject() + "  영어 : " + info.getEng().getSubject()
                    + "  수학 : " + info.getMat().getSubject() + "  총점 : " + info.getTotal() + "  평균 : " + info.getAvg());
        } else
            System.out.println("출력할 데이터가 존재하지않습니다");
    }
 
    public TreeSet<StudentInfo> listSort_name(TreeSet<StudentInfo> arr) {// 이름기준으로 오름차순 정렬
        TreeSet<StudentInfo> temp = new TreeSet<>(new Comparator<StudentInfo>() {
 
            @Override
            public int compare(StudentInfo o1, StudentInfo o2) {
                if (o1.getName().compareTo(o2.getName()) < 0) {
                    return -1;
                } else if (o1.getName().compareTo(o2.getName()) > 0) {
                    return 1;
                } else
                    return -1;
            }
        });
        temp.addAll(arr);
        return temp;
    }
 
    public NavigableSet<StudentInfo> listSort_total(TreeSet<StudentInfo> arr) {// 총점 내림차순으로 출력
        NavigableSet<StudentInfo> decendingSet = arr.descendingSet();
        return decendingSet;
    }
 
    public TreeSet<StudentInfo> listSort_std_department(TreeSet<StudentInfo> arr) {// 학과기준으로 오름차순 정렬
        TreeSet<StudentInfo> temp = new TreeSet<>(new Comparator<StudentInfo>() {
 
            @Override
            public int compare(StudentInfo o1, StudentInfo o2) {
                if (o1.getStd_department().compareTo(o2.getStd_department()) < 0) {
                    return -1;
                } else if (o1.getStd_department().compareTo(o2.getStd_department()) > 0) {
                    return 1;
                } else
                    return -1;
            }
        });
        temp.addAll(arr);
        return temp;
    }
 
    public void searchInfo_stdName(TreeSet<StudentInfo> arr, String value) {// 이름으로 리스트 검색
        Iterator<StudentInfo> iterator = arr.iterator();
        while (iterator.hasNext()) {
            StudentInfo temp = iterator.next();
            if (temp.getName().equals(value))
                dispInfo(temp);
        }
 
    }
 
    public void searchInfo_stdDepartment(TreeSet<StudentInfo> arr, String value) {// 학과로 리스트 검색
        Iterator<StudentInfo> iterator = arr.iterator();
        while (iterator.hasNext()) {
            StudentInfo temp = iterator.next();
            if (temp.getStd_department().equals(value))
                dispInfo(temp);
        }
    }
 
    public void searchInfo_stdId(TreeSet<StudentInfo> arr, String value) {// 사번으로 리스트 검색
        Iterator<StudentInfo> iterator = arr.iterator();
        while (iterator.hasNext()) {
            StudentInfo temp = iterator.next();
            if (temp.getStd_id().equals(value))
                dispInfo(temp);
        }
    }
 
    public void StudentInfo_delete(TreeSet<StudentInfo> arr, Scanner sc) {
 
        System.out.print("삭제할 학생의 사번을 입력하시오 : ");
        String std_id = sc.next();
        for (Iterator<StudentInfo> iterator = arr.iterator(); iterator.hasNext();) {
            StudentInfo info = iterator.next();
            if (info.getStd_id().equals(std_id)) {
                iterator.remove();
                break;
            }
        }
 
    }
 
    public void StudentInfo_modify(TreeSet<StudentInfo> arr, int opt5, String value_opt5, String std_id)
            throws Exception {
        StudentInfo info = null;
        int cnt = 0;
        Iterator<StudentInfo> iterator = arr.iterator();
        while (iterator.hasNext()) {
            StudentInfo temp = iterator.next();
            if (temp.getStd_id().equals(std_id))
                info = temp;
 
        }
        if (info == null)
            throw new Exception();// 해당 학번이 리스트에 존재하지 않을경우 예외 발생
        switch (opt5) {
        case 1:
            info.setName(value_opt5);
            // arr[i]. = new StudentInfo(info.getStd_id(), std_id, std_id, opt5, opt5,
            // opt5);
            break;
        case 2:
            info.setStd_department(value_opt5);
            break;
        case 3:
            info.setKor(Integer.valueOf(value_opt5));
            break;
        case 4:
            info.setKor(Integer.valueOf(value_opt5));
            break;
        case 5:
            info.setKor(Integer.valueOf(value_opt5));
            break;
 
        default:
            break;
        }
    }
}
 
cs

GUI.class

package project_0707;
 
import java.util.*;
 
public class Gui {
 
    public void exe() {
 
        Scanner sc = new Scanner(System.in);
        TreeSet<StudentInfo> arr = new TreeSet<>(new Comparator<StudentInfo>() {
 
            @Override
            public int compare(StudentInfo o1, StudentInfo o2) {
                if (o1.getTotal() < o2.getTotal())
                    return -1;
                else if (o1.getTotal() == o2.getTotal())
                    return 0;
                else
                    return 1;
            }
        });
        InformationManagement im = new InformationManagement();
        outwhile (true) {
            System.out.print("1.입력  2.출력  3.검색  4.삭제  5.수정  6.종료  ==>    ");
            switch (sc.nextInt()) {
            case 1:
                try {
                    im.insertInfo(arr, sc);//
                } catch (Exception e) {
                    e.printStackTrace();
                    // System.out.println("해당 학번은 이미 사용중입니다 다시 입력해주십시오");
                }
 
                break;
            case 2:
                System.out.print("정렬기준 : 1.등록   2.총점   3.이름  4.학과   ==>");
                switch (sc.nextInt()) {
                case 1:
                    im.dispALLInfo(arr);// 등록순으로 출력
                    break;
                case 2:
                    im.dispALLInfo(im.listSort_total(arr));// 라스트출력(return 총점순으로 정렬된 리스트)
                    break;
                case 3:
                    im.dispALLInfo(im.listSort_name(arr));// 라스트출력(return 이름으로 정렬된 리스트)
                    break;
                case 4:
                    im.dispALLInfo(im.listSort_std_department(arr));// 라스트출력(return 학과이름순으로 정렬된 리스트
 
                    break;
                default:
                    System.out.println("형식에 맞지 않는 입력값입니다");
                    break;
                }
 
                break;
            case 3:
                System.out.print("감색기준 : 1.학번   2.이름   3.학과  ==>");
                int opt_3 = sc.nextInt();
                System.out.print("검색정보를 입력하시오 : ");
                String value = sc.next();
                switch (opt_3) {
                case 1:
                    im.searchInfo_stdId(arr, value);
                    break;
                case 2:
                    im.searchInfo_stdName(arr, value);
                    break;
                case 3:
                    im.searchInfo_stdDepartment(arr, value);
                    break;
 
                default:
                    System.out.println("형식에 맞지 않는 입력값입니다");
                    break;
                }
 
                break;
            case 4:
                im.dispALLInfo(arr);// 삭제 전 학생 정보 출력
                im.StudentInfo_delete(arr, sc);
                im.dispALLInfo(arr);// 삭제 후 학생 정보 출력
                break;
            case 5:
                System.out.print("수정할 학생의 사번을 입력하시오 : ");
                String std_id = sc.next();
                System.out.print("수정항목 :  1.이름   2.학과   3.국어   4.영어   5.수학  ==>");
                int opt5 = sc.nextInt();
                System.out.print("수정정보를 입력하시오 : ");
                String value_opt5 = sc.next();
                try {
                    im.StudentInfo_modify(arr, opt5, value_opt5, std_id);
                } catch (Exception e) {
                    System.out.println("해당 학번이 존재하지 않습니다");
                }
 
                break;
            case 6:
                break out;
            default:
                System.out.println("형식에 맞지 않는 입력값입니다");
                break;
            }
        }
 
    }
}
 
cs

'비트교육_단기과정' 카테고리의 다른 글

로또 : 마기창  (0) 2022.07.11
Map<E> 성적관리  (0) 2022.07.08
List를 사용한 성적관리  (0) 2022.07.07
Generic Memory  (0) 2022.07.06
스레드 동기화(ATM 번갈아서) : 마기창  (0) 2022.07.05
Contents

포스팅 주소를 복사했습니다

이 글이 도움이 되었다면 공감 부탁드립니다.