비트교육_단기과정
Map<E> 성적관리
- -
학생정보관리.class
package project_0707; import java.util.*; public class InformationManagement { public boolean overlapCheck(TreeMap<String, StudentInfo> arr, String std_id) throws Exception {// 학번 중복체크 중복이면 예외발생 // 중복이아니면 false 반환 boolean flag = arr.containsKey(std_id); if (flag) throw new Exception(); else return flag; } public void insertInfo(TreeMap<String, 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.put(std_id, studentInfo); } public void dispALLInfo(Map<String, StudentInfo> arr) {// 리스트 전체출력 if (!arr.isEmpty()) { Set<String> ketys = arr.keySet(); System.out.println("======학생 정보 출력======"); for (String info : ketys) { dispInfo(arr.get(info)); } } else System.out.println("출력할 데이터가 존재하지않습니다"); } public void dispALLInfo(List<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 List<StudentInfo> listSort_name(TreeMap<String, StudentInfo> arr) {// 이름 오룸차순으로 정렬 List<StudentInfo> temp = new ArrayList<>(arr.values()); Collections.sort(temp, new Comparator<StudentInfo>() { @Override public int compare(StudentInfo std1, StudentInfo std2) { return std1.getName().compareTo(std2.getName()); } }); return temp; } public List<StudentInfo> listSort_total(TreeMap<String, StudentInfo> arr) {// 총점 내림차순으로 출력 NavigableMap<String, StudentInfo> decendingSet = arr.descendingMap(); List<StudentInfo> temp = new ArrayList<>(decendingSet.values()); Collections.sort(temp, new Comparator<StudentInfo>() { @Override public int compare(StudentInfo o1, StudentInfo o2) { if (o1.getKor().getSubject() < o2.getKor().getSubject()) { return 1; } else if (o1.getKor().getSubject() == o2.getKor().getSubject()) { return -1; } else return -1; } }); return temp; } public List<StudentInfo> listSort_std_department(TreeMap<String, StudentInfo> arr) {// 학과기준으로 오름차순 정렬 List<StudentInfo> temp = new ArrayList<>(arr.values()); Collections.sort(temp, new Comparator<StudentInfo>() { @Override public int compare(StudentInfo std1, StudentInfo std2) { return std1.getStd_department().compareTo(std2.getStd_department()); } }); return temp; } public void searchInfo_stdName(TreeMap<String, StudentInfo> arr, String value) {// 이름으로 리스트 검색 List<StudentInfo> temp = new ArrayList<>(arr.values()); for (StudentInfo info : temp) { if (value.equals(info.getName())) { dispInfo(info); } } } public void searchInfo_stdDepartment(TreeMap<String, StudentInfo> arr, String value) {// 학과로 리스트 검색 List<StudentInfo> temp = new ArrayList<>(arr.values()); for (StudentInfo info : temp) { if (value.equals(info.getStd_department())) { dispInfo(info); } } } public void searchInfo_stdId(TreeMap<String, StudentInfo> arr, String value) {// 학번으로 리스트 검색 List<StudentInfo> temp = new ArrayList<>(arr.values()); for (StudentInfo info : temp) { if (value.equals(info.getStd_id())) { dispInfo(info); } } } public void searchScoreKor(TreeMap<String, StudentInfo> arr, int score) {// 과목점수 커트라인으로 출력 TreeSet<StudentInfo> temp = new TreeSet<>(new Comparator<StudentInfo>() { @Override public int compare(StudentInfo o1, StudentInfo o2) { if (o1.getKor().getSubject() < o2.getKor().getSubject()) { return 1; } else if (o1.getKor().getSubject() == o2.getKor().getSubject()) { return -1; } else return -1; } }); temp.addAll(arr.values()); for (StudentInfo info : temp) { if (info.getKor().getSubject() > score) { dispInfo(info); } } } public void searchScoreEng(TreeMap<String, StudentInfo> arr, int score) {// 과목점수 커트라인으로 출력 TreeSet<StudentInfo> temp = new TreeSet<>(new Comparator<StudentInfo>() { @Override public int compare(StudentInfo o1, StudentInfo o2) { if (o1.getEng().getSubject() < o2.getEng().getSubject()) { return 1; } else if (o1.getEng().getSubject() == o2.getEng().getSubject()) { return -1; } else return -1; } }); temp.addAll(arr.values()); for (StudentInfo info : temp) { if (info.getEng().getSubject() > score) { dispInfo(info); } } } public void searchScoreMat(TreeMap<String, StudentInfo> arr, int score) {// 과목점수 커트라인으로 출력 TreeSet<StudentInfo> temp = new TreeSet<>(new Comparator<StudentInfo>() { @Override public int compare(StudentInfo o1, StudentInfo o2) { if (o1.getMat().getSubject() < o2.getMat().getSubject()) { return 1; } else if (o1.getMat().getSubject() == o2.getMat().getSubject()) { return -1; } else return -1; } }); temp.addAll(arr.values()); for (StudentInfo info : temp) { if (info.getMat().getSubject() > score) { dispInfo(info); } } } public void StudentInfo_delete(TreeMap<String, StudentInfo> arr, Scanner sc) {// 해당 학번의 학생의 정보를 삭제 System.out.print("삭제할 학생의 학번을 입력하시오 : "); String std_id = sc.next(); arr.remove(std_id); } public void StudentInfo_modify(TreeMap<String, StudentInfo> arr, int opt5, String value_opt5, String std_id) throws Exception { StudentInfo info = null; info = arr.get(std_id); // 맵에서 해당 학번에 맞는 객체 반환 if (info == null) throw new Exception();// 해당 학번이 리스트에 존재하지 않을경우 예외 발생 switch (opt5) { case 1: info.setName(value_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); TreeMap<String, StudentInfo> arr = new TreeMap<String, StudentInfo>(); InformationManagement im = new InformationManagement(); out: while (true) { System.out.print("1.입력 2.출력 3.검색 4.삭제 5.수정 6.종료 ==> "); switch (sc.nextInt()) { case 1: try { im.insertInfo(arr, sc);// } catch (Exception e) { System.out.println("해당 학번은 이미 사용중입니다 다시 입력해주십시오"); } break; case 2: System.out.print("정렬기준 : 1.등록 2.총점 3.이름 4.학과 5.과목점수 ==>"); 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; case 5: System.out.print("과목 : 1.국어 2.영어 3.수학 ==>"); int opt = sc.nextInt(); System.out.print("커트라인을 입력하시오 : "); int score_cutline = sc.nextInt(); switch (opt) { case 1: im.searchScoreKor(arr, score_cutline); break; case 2: im.searchScoreEng(arr, score_cutline); break; case 3: im.searchScoreMat(arr, score_cutline); break; default: System.out.println("형식에 맞지 않는 입력값입니다"); break; } 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 |
'비트교육_단기과정' 카테고리의 다른 글
알고리즘 1번 문제 (0) | 2022.07.11 |
---|---|
로또 : 마기창 (0) | 2022.07.11 |
Set<E> 성적관리 (0) | 2022.07.08 |
List를 사용한 성적관리 (0) | 2022.07.07 |
Generic Memory (0) | 2022.07.06 |
Contents
소중한 공감 감사합니다