diff --git a/src/src/service/AdminService.java b/src/src/service/AdminService.java index ef88607..aad04f8 100644 --- a/src/src/service/AdminService.java +++ b/src/src/service/AdminService.java @@ -4,29 +4,23 @@ import src.domain.*; import src.repository.Repository; import src.repository.RepositoryProvider; -import src.repository.TeacherRepository; import java.io.IOException; import java.time.LocalDate; import java.time.LocalDateTime; import java.time.Period; -import java.time.format.DateTimeFormatter; import java.util.ArrayList; import java.util.List; import java.util.Queue; -import java.util.Scanner; -import java.util.regex.Matcher; -import java.util.regex.Pattern; public class AdminService { - - private Repository studentRepository; - private Repository teacherRepository; - private Repository lectureRepository; - private Repository notificationRepository; - private Bank bank = new Bank(); + private Repository studentRepository; + private Repository teacherRepository; + private Repository lectureRepository; + private Repository notificationRepository; + private Bank bank; private Admin admin; private LocalDate lastPaymentDay; @@ -36,63 +30,64 @@ public AdminService() throws IOException { this.teacherRepository = RepositoryProvider.getInstance().provide(ServiceType.TEACHER); this.lectureRepository = RepositoryProvider.getInstance().provide(ServiceType.LECTURE); this.notificationRepository = RepositoryProvider.getInstance().provide(ServiceType.NOTIFICATION); - this.lastPaymentDay = LocalDate.of(2024,2,26); + this.bank = new Bank(); + this.lastPaymentDay = LocalDate.of(2024, 2, 26); } - public Admin getAdmin(){ + + public Admin getAdmin() { return this.admin; } - public void setAdmin(Admin admin){ + + public void setAdmin(Admin admin) { this.admin = admin; } - public boolean checkInAmsAccount(String accountNumber){ + public boolean checkInAmsAccount(String accountNumber) { return bank.checkAmsAccount(accountNumber); } //학원결제시스템 - public void bankSystem() throws IOException { + public void doPaymentSystem() throws IOException { LocalDate nowDate = LocalDate.now(); - if(lastPaymentDay!=null && Period.between(lastPaymentDay,nowDate).getMonths()!=1){ + if (lastPaymentDay != null && Period.between(lastPaymentDay, nowDate).getMonths() != 1) { System.out.println("[오늘은 결제일이 아닙니다!]"); - System.out.println("[다음 결제일]: "+lastPaymentDay.plusMonths(1)); + System.out.println("[다음 결제일]: " + lastPaymentDay.plusMonths(1)); return; } lastPaymentDay = nowDate; - - List studentList = studentRepository.findAll(); List successList = new ArrayList<>(); List failList = new ArrayList<>(); for (Student student : studentList) { boolean checkAccount = bank.checkAccount(student.getAccountNumber(), student.getAccountPassword()); - boolean paymentAccount = bank.paymentAccount(student.getAccountNumber(), student.getLectureCost()); + boolean paymentAccount = bank.accountTransfer(student.getAccountNumber(), student.getLectureCost()); System.out.println(student.getLectureCost()); - Long result = bank.finalBalance(student.getAccountNumber());//결제가 완료되고 남은 학생 잔액 + Long result = bank.getBalance(student.getAccountNumber());//결제가 완료되고 남은 학생 잔액 String adminContent = ""; String studentContent = ""; - if(checkAccount){ - if(paymentAccount){ + if (checkAccount) { + if (paymentAccount) { adminContent = "납부완료"; studentContent = "회원님의 계좌에서 정상적으로 출금을 완료하였습니다."; successList.add(student.getName()); - } else{ + } else { adminContent = "미납대상"; studentContent = "계좌의 잔액부족으로 출금이 실패하였습니다."; failList.add(student.getName()); } - } else{ + } else { adminContent = "미납대상"; studentContent = "계좌정보미일치로 인해 출금이 실패하였습니다."; failList.add(student.getName()); } - Notification notification = new Notification(1,0,adminContent ,studentContent ,student.getId(),LocalDateTime.now(),result); + Notification notification = new Notification(1, 0, adminContent, studentContent, student.getId(), LocalDateTime.now(), result); Queue notificationQ = (Queue) notificationRepository.findById(student.getId()); - if(notificationQ.size() >= 10) { + if (notificationQ.size() >= 10) { notificationQ.poll(); } notificationQ.add(notification); @@ -106,9 +101,9 @@ public void bankSystem() throws IOException { System.out.println("학원비 미납: " + failList.size() + "명"); System.out.println("----------------------------------"); System.out.println(" [학원비 미납자]"); - for(String name : failList) { + for (String name : failList) { System.out.println("*********************************"); - System.out.println(" "+name+" "); + System.out.println(" " + name + " "); System.out.println("*********************************"); } } @@ -116,22 +111,22 @@ public void bankSystem() throws IOException { //수정할 수 있는 수정메뉴 출력 public boolean showStudentInformation(String studentId) throws IOException { Student student = studentRepository.findById(studentId); - if(student == null) { + if (student == null) { System.out.println("입력 아이디에 해당하는 학생정보가 없습니다."); return false; } - student.editStudentInformation(); + student.printEditStudentInformation(); return true; } //수정할 수 있는 수정메뉴 출력 public boolean showTeacherInformation(String teacherId) throws IOException { Teacher teacher = teacherRepository.findById(teacherId); - if(teacher == null) { + if (teacher == null) { System.out.println("입력 아이디에 해당하는 강사정보가 없습니다."); return false; - } - teacher.editTeacherInformation(); + } + teacher.printEditTeacherInformation(); return true; } @@ -139,25 +134,20 @@ public boolean showTeacherInformation(String teacherId) throws IOException { public void showStudentList() throws IOException { List StudentList = studentRepository.findAll(); - if(StudentList.isEmpty()){ + if (StudentList.isEmpty()) { System.out.println(" [현재 등록중인 학생이 없습니다.]"); } - System.out.println(" [학생리스트] "); + System.out.println(" [학생리스트] "); System.out.println("**********************************"); for (Student student : StudentList) { student.printStudentInformation(); } } - //학생아이디가 존재하는지 확인 - public boolean isExistStudent(String studentId) { - return studentRepository.isExist(studentId); - } - //1. (입력받은 아이디의 학생)상세정보출력 public boolean detailStudentInformation(String studentId) throws IOException { Student student = studentRepository.findById(studentId); - if(student == null) { + if (student == null) { System.out.println("입력 아이디에 해당하는 학생정보가 없습니다."); return false; } @@ -166,7 +156,7 @@ public boolean detailStudentInformation(String studentId) throws IOException { } //2. 학생정보 수정 - public void newEditStudentInformation(String studentId, int option, String value) throws IOException { + public void editStudentInformation(String studentId, int option, String value) throws IOException { Student student = studentRepository.findById(studentId);//수정할 학생 찾음 switch (option) { @@ -202,9 +192,9 @@ public void newEditStudentInformation(String studentId, int option, String value } //학생정보 삭제 - public boolean newDeleteStudentInformation(String studentId) throws IOException { + public boolean deleteStudentInformation(String studentId) throws IOException { Student student = studentRepository.findById(studentId); - if(student == null) { + if (student == null) { System.out.println("입력 아이디에 해당하는 학생정보가 없습니다!"); System.out.println(); return false; @@ -229,7 +219,7 @@ public void showTeacherList() throws IOException { //1. (입력받은 아이디의 강사)상세정보출력 public boolean detailTeacherInformation(String teacherId) throws IOException { Teacher teacher = teacherRepository.findById(teacherId); - if(teacher == null) { + if (teacher == null) { System.out.println("입력 아이디에 해당하는 강사정보가 없습니다."); return false; } @@ -238,7 +228,7 @@ public boolean detailTeacherInformation(String teacherId) throws IOException { } //2. 강사정보 수정 - public void newEditTeacherInformation(String teacherId, int option, String value) throws IOException { + public void editTeacherInformation(String teacherId, int option, String value) throws IOException { Teacher teacher = teacherRepository.findById(teacherId);//수정할 학생 찾음 switch (option) { @@ -270,9 +260,9 @@ public void newEditTeacherInformation(String teacherId, int option, String value } //강사정보 삭제 - public boolean newDeleteTeacherInformation(String teacherId) throws IOException { + public boolean deleteTeacherInformation(String teacherId) throws IOException { Teacher teacher = teacherRepository.findById(teacherId); - if(teacher == null) { + if (teacher == null) { System.out.println("입력 아이디에 해당하는 강사정보가 없습니다."); return false; } @@ -289,7 +279,7 @@ public void showLectureList() throws IOException { System.out.println(" [강의리스트] "); System.out.println("*********************************************"); - if(LectureList.isEmpty()){ + if (LectureList.isEmpty()) { System.out.println(" [현재 등록된 강의는 없습니다.]"); return; } @@ -311,7 +301,7 @@ public void showDetailLectureList() throws IOException { //1. (입력받은 아이디의 학생)상세정보출력 public boolean detailLectureInformation(String lectureId) throws IOException { Lecture lecture = lectureRepository.findById(lectureId); - if(lecture == null) { + if (lecture == null) { System.out.println("입력 아이디에 해당하는 강의정보가 없습니다."); return false; } @@ -321,14 +311,11 @@ public boolean detailLectureInformation(String lectureId) throws IOException { //2.새로운 강의 등록 - public void registerLecture(String name,int day,int time, String teacherName, String teacherId) throws IOException { + public void registerLecture(String name, int day, int time, String teacherName, String teacherId) throws IOException { int id = lectureRepository.findAll().size() + 1; // 코드 수정 필요 Lecture lecture = new Lecture(name + id, name, day, time, teacherName, teacherId); -// lecture.setLectureRegistrationList(new ArrayList<>()); -// lecture.setLectureRegistrationIdList(new ArrayList<>()); - Teacher teacher = teacherRepository.findById(teacherId); List lectureList = teacher.getLectureList(); List lectureIdList = teacher.getLectureIdList(); @@ -351,7 +338,7 @@ public boolean isExistSameTimeLecture(String teacherId, int day, int time) throw Teacher teacher = teacherRepository.findById(teacherId); List lectureList = teacher.getLectureList(); - if(lectureList.isEmpty()){ + if (lectureList.isEmpty()) { return false; } for (Lecture lecture : lectureList) { @@ -362,29 +349,16 @@ public boolean isExistSameTimeLecture(String teacherId, int day, int time) throw return false; } - //강사 아이디로 강사 이름반환 public String getTeacherName(String teacherId) throws IOException { return teacherRepository.findById(teacherId).getName(); } - //3. 강의삭제 - public void deleteLectureInformation() throws IOException { - Scanner sc = new Scanner(System.in); - System.out.print("삭제하실 강의 아이디를 입력해주세요: "); - - String LectureId = sc.nextLine();//삭제할 강의 아이디 입력 - Lecture targetDeleteLecture = lectureRepository.findById(LectureId); - lectureRepository.delete(targetDeleteLecture); - System.out.println("입력하신 강의정보가 삭제되었습니다."); - lectureRepository.save(); - } - //강의정보 삭제 - public boolean newDeleteLectureInformation(String lectureId) throws IOException { + public boolean deleteLectureInformation(String lectureId) throws IOException { Lecture lecture = lectureRepository.findById(lectureId); - if(lecture == null) { + if (lecture == null) { System.out.println("입력 아이디에 해당하는 강의정보가 없습니다."); return false; } diff --git a/src/src/service/StudentService.java b/src/src/service/StudentService.java index a15ae4d..bbde06e 100644 --- a/src/src/service/StudentService.java +++ b/src/src/service/StudentService.java @@ -2,19 +2,15 @@ import java.io.IOException; import java.util.List; -import java.util.Objects; import java.util.Queue; -import java.util.Scanner; -import java.util.logging.Level; import java.util.stream.Collectors; -import javax.management.QueryEval; + import src.ServiceType; import src.domain.Lecture; import src.domain.LectureRegistration; import src.domain.Notification; import src.domain.Student; import src.domain.StudyRoom; -import src.domain.Teacher; import src.repository.Repository; import src.repository.RepositoryProvider; @@ -26,81 +22,57 @@ public class StudentService { // 알림 repo 불러오기 private Repository notificationRepository; private Repository studentRepository; - private Repository teacherRepository; private StudyRoom studyRoom; private Student student; - - public StudentService() throws IOException { this.lectureRepository = RepositoryProvider.getInstance().provide(ServiceType.LECTURE); this.lectureRegistrationRepository = RepositoryProvider.getInstance().provide(ServiceType.LECTUREREGISTRATION); this.notificationRepository = RepositoryProvider.getInstance().provide(ServiceType.NOTIFICATION); this.studentRepository = RepositoryProvider.getInstance().provide(ServiceType.STUDENT); - this.teacherRepository = RepositoryProvider.getInstance().provide(ServiceType.TEACHER); this.studyRoom = new StudyRoom(); } - public Student getStudent(){ + public Student getStudent() { return student; } - public void setStudent(Student student){ + public void setStudent(Student student) { this.student = student; } - /////////////////////////////////////////////////////////////////////////////////////////////////////////// - - - /////////////////////////////////////////////////////////////////////////////////////////////////////////// - // 0. 학생으로 로그인 후 첫 페이지인 메뉴 보이기 - - - - - // 1. 수강 관리 - // 전체 강의 리스트 출력 public void showAllLectureList() throws IOException { // lectureRepository 에서 findAll() 메서드 호출 List allLectures = lectureRepository.findAll(); System.out.println(); System.out.println("------------------------------------------[수강 가능한 강의 목록]------------------------------------------"); - //System.out.println("-----------------------------------------------------------------------------------------------------"); - // 가져온 강의 목록 처리 for (Lecture lecture : allLectures) { System.out.print("강의 ID: " + lecture.getLectureId() + " "); System.out.print("강의 이름: " + lecture.getLectureName() + " "); System.out.print("강의 요일: " + intLectureDayToRealDay(lecture.getLectureTime()) + " "); // 숫자 -> 요일 System.out.print("강의 시간: " + intLectureTimeToRealTime(lecture.getLectureTime()) + " "); // 숫자 -> realtime System.out.println("강사: " + lecture.getLectureTeacherName() + " "); - //System.out.println(); // 강의 사이에 공백 라인 추가 } System.out.println("--------------------------------------------------------------------------------------------------------\n"); } // 수강 신청 내역 가져와 출력 - public boolean showStudentAllRegistrationLecture() throws IOException { + public boolean showLectureRegistrationList() throws IOException { //수강 신청 내역 가져오기 //필터링 (해당 학생의 수강 신청 내역) List studentLectureRegistration = lectureRegistrationRepository.findAll().stream() .filter(registration -> registration.getStudentId().equals(student.getId())) .collect(Collectors.toList()); - if(studentLectureRegistration.isEmpty()) { + if (studentLectureRegistration.isEmpty()) { System.out.println("수강 신청 내역이 존재하지 않습니다.\n"); return false; } // 해당 학생 수강 신청 내역 출력 - //System.out.println("\n[수강 신청 내역]"); System.out.println("\n---------------------------------------------[수강 신청 내역]-------------------------------------------"); - for(LectureRegistration lectureRegistration : studentLectureRegistration) { -// System.out.println( -// "수강신청ID: " + lectureRegistration.getId() + ", 강의ID: " + lectureRegistration.getLectureId() -// + ", 학생ID: " + lectureRegistration.getStudentId() + ", 강의요일: " -// + lectureRegistration.getLectureDay() + -// ", 강의시간: " + intLectureTimeToRealTime(lectureRegistration.getLectureTime())); + for (LectureRegistration lectureRegistration : studentLectureRegistration) { System.out.print("강의 ID: " + lectureRegistration.getLectureId() + " "); System.out.print("학생 ID: " + lectureRegistration.getStudentId() + " "); System.out.print("강의 요일: " + lectureRegistration.getLectureDay() + " "); @@ -110,19 +82,18 @@ public boolean showStudentAllRegistrationLecture() throws IOException { return true; } - // 강의 요일 (int -> str) 바꿔주는 함수 // lectureDay를 숫자로 받으면 각 번호에 맞는 요일로 리턴 - String intLectureDayToRealDay (int lectureDay) { - if(lectureDay == 0){ + String intLectureDayToRealDay(int lectureDay) { + if (lectureDay == 0) { return "월요일"; - } else if(lectureDay == 1){ + } else if (lectureDay == 1) { return "화요일"; - } else if(lectureDay == 2){ + } else if (lectureDay == 2) { return "수요일"; - } else if(lectureDay == 3){ + } else if (lectureDay == 3) { return "목요일"; - } else if(lectureDay == 4){ + } else if (lectureDay == 4) { return "금요일"; } return null; @@ -130,23 +101,21 @@ String intLectureDayToRealDay (int lectureDay) { // 강의 시간 숫자를 실제 시간으로 바꿔주는 함수 // lectureTime을 숫자로 받으면 각 번호에 맞는 시간으로 리턴 - String intLectureTimeToRealTime (int lectureTime) {if(lectureTime == 0){ - return "10:00 ~ 12:00"; - } else if(lectureTime == 1){ + String intLectureTimeToRealTime(int lectureTime) { + if (lectureTime == 0) { + return "10:00 ~ 12:00"; + } else if (lectureTime == 1) { return "13:00 ~ 14:50"; - } else if(lectureTime == 2){ + } else if (lectureTime == 2) { return "15:00 ~ 16:50"; - } else if(lectureTime == 3){ + } else if (lectureTime == 3) { return "17:00 ~ 19:00"; } return null; } - // 수강 신청 - public void registerLecture(String choiceLectureId) throws IOException { - - + public void registerLectureRegistration(String choiceLectureId) throws IOException { // 강의 리스트에서 해당 강의 정보 가져오기 Lecture pickLecture = lectureRepository.findById(choiceLectureId); if (pickLecture == null) { @@ -187,7 +156,7 @@ public void registerLecture(String choiceLectureId) throws IOException { } // 수강 취소 - public void deleteLecture(String lectureId) throws IOException { + public void deleteLectureRegistration(String lectureId) throws IOException { // 내 시간표에 해당 id 강의가 있는지 확인 후 삭제 또는 취소 실패 문구 출력 List studentTimetable = student.getLectureRegistrationList(); @@ -203,11 +172,10 @@ public void deleteLecture(String lectureId) throws IOException { if (isCancelled) { System.out.println("\n수강이 취소되었습니다.\n"); - student.setLectureCost(student.getLectureCost()-100000L); //수강취소후 강의료 환불 + student.setLectureCost(student.getLectureCost() - 100000L); //수강취소후 강의료 환불 } else { System.out.println("\n해당 강의를 수강하고 있지 않습니다.\n"); } - } // 자습실 좌석표 출력 @@ -221,7 +189,8 @@ public void showStudyRoom() { // 예약된 좌석은 'X', 예약 가능한 좌석은 좌석 번호 표시 if (studyRoom.getCheckSeat()[i][j]) { // 예약좌석이 내 좌석인지 다른 사람 좌석인지 체크 - if(reservationInformation!=null &&reservationInformation.equals((i+1) + "-" + (j+1))) System.out.printf("[%s] ", "내좌석"); + if (reservationInformation != null && reservationInformation.equals((i + 1) + "-" + (j + 1))) + System.out.printf("[%s] ", "내좌석"); else System.out.printf("[%s] ", "X"); } else { System.out.printf("[%d-%d] ", i + 1, j + 1); @@ -232,9 +201,9 @@ public void showStudyRoom() { System.out.println("******************************\n"); } - public boolean isExistResevation(){ + public boolean isExistReservation() { if (studyRoom.getReservationMap().containsKey(student.getId())) { - System.out.println("["+student.getName()+"님] 이미 예약된 좌석이 있습니다.\n"); + System.out.println("[" + student.getName() + "님] 이미 예약된 좌석이 있습니다.\n"); return true; } return false; @@ -242,7 +211,7 @@ public boolean isExistResevation(){ // 좌석 예약 // 좌석 번호 입력 후 예약 가능 여부 확인 - public boolean isPossibleReserve(String choiceSeat) { + public boolean reserveStudyRoom(String choiceSeat) { // 이미 예약 기록이 있을 때, '당일 이미 예약된 좌석이 있습니다.' 출력 System.out.println(); int x = -1; @@ -263,32 +232,27 @@ public boolean isPossibleReserve(String choiceSeat) { System.out.println("잘못된 좌석 번호입니다.\n"); return false; } - // 좌석이 이미 예약된 경우 if (studyRoom.getCheckSeat()[x][y]) { - System.out.println("이미 예약된 좌석입니다.\n"); + System.out.println("\n이미 예약된 좌석입니다.\n"); return false; } - // 만약 이미 이 학생의 당일 예약 기록이 있다면 if (studyRoom.getReservationMap().containsKey(student.getId())) { System.out.println("이미 예약한 좌석이 있습니다.\n"); System.out.println("예약한 좌석 : " + studyRoom.getReservationMap().get(student.getId())); return false; } - // 예약 가능한 경우 (잘못된 좌석 번호 X, 이미 예약된 좌석 X, 당일 예약 기록 X) // 해당 좌석 예약 studyRoom.getCheckSeat()[x][y] = true; // 학생 아이디와 좌석 번호 맵에 저장 studyRoom.getReservationMap().put(student.getId(), String.valueOf(choiceSeat)); - System.out.println("좌석이 성공적으로 예약되었습니다.\n"); - return true; // 예약 성공 } -// + // 자습실 예약 취소 public boolean cancelReservation(String seatNum) { int x = -1; @@ -304,14 +268,11 @@ public boolean cancelReservation(String seatNum) { System.out.println("\n좌석 번호가 유효하지 않습니다.\n"); return false; } - - // 좌석 번호 유효성 검사 if (x < 0 || x >= studyRoom.getCheckSeat().length || y < 0 || y >= studyRoom.getCheckSeat()[0].length) { System.out.println("\n잘못된 좌석 번호입니다.\n"); return false; } - // 예약된 좌석인지 확인하고 해당 학생의 예약인지 검사 if (studyRoom.getReservationMap().containsKey(student.getId()) && // 내 좌석이 있는지 studyRoom.getReservationMap().get(student.getId()).equals(seatNum)) { // 내가 입력한 좌석 번호와 일치하는지 @@ -330,10 +291,10 @@ public boolean cancelReservation(String seatNum) { //학생알림함 제공 public void checkNotification() throws IOException { System.out.println("-----------[결제알림함]-----------"); - if(notificationRepository.isExist(student.getId())){ + if (notificationRepository.isExist(student.getId())) { Queue notificationQueue = (Queue) notificationRepository.findById(student.getId()); for (Notification notification : notificationQueue) { - if(notification.getCheckCount() != 0){ + if (notification.getCheckCount() != 0) { System.out.println("[읽음] " + "메세지 내용: " + notification.getStudentContent()); System.out.println("[잔액]: " + notification.getBalance()); } else { @@ -346,5 +307,4 @@ public void checkNotification() throws IOException { System.out.println(" [수신된 알림이 없습니다.] "); } } - } diff --git a/src/src/service/TeacherService.java b/src/src/service/TeacherService.java index 8dc8aed..d4bb9fa 100644 --- a/src/src/service/TeacherService.java +++ b/src/src/service/TeacherService.java @@ -9,18 +9,18 @@ import src.repository.RepositoryProvider; import java.io.IOException; -import java.sql.SQLOutput; import java.util.List; import java.util.Optional; public class TeacherService { private Teacher teacher; - private Repository studentRepository; + private Repository studentRepository; public TeacherService() throws IOException { this.studentRepository = RepositoryProvider.getInstance().provide(ServiceType.STUDENT); } - public Teacher getTeacher(){ + + public Teacher getTeacher() { return this.teacher; } @@ -28,38 +28,37 @@ public void setTeacher(Teacher teacher) { this.teacher = teacher; } - /** * 강사의 강의 리스트를 보여주는 함수 */ - public void showLectureList(){ - if(teacher.getLectureList().isEmpty()){ + public void showLectureList() { + if (teacher.getLectureList().isEmpty()) { System.out.println(" [현재 담당하고있는 강의가 없습니다.]"); return; } - for(Lecture lecture: teacher.getLectureList()){ + for (Lecture lecture : teacher.getLectureList()) { String realLectureDay = ""; - if(lecture.getLectureDay() == 0){ + if (lecture.getLectureDay() == 0) { realLectureDay = "월요일"; - } else if(lecture.getLectureDay() == 1){ + } else if (lecture.getLectureDay() == 1) { realLectureDay = "화요일"; - } else if(lecture.getLectureDay() == 2){ + } else if (lecture.getLectureDay() == 2) { realLectureDay = "수요일"; - } else if(lecture.getLectureDay() == 3){ + } else if (lecture.getLectureDay() == 3) { realLectureDay = "목요일"; - } else if(lecture.getLectureDay() == 4){ + } else if (lecture.getLectureDay() == 4) { realLectureDay = "금요일"; } String realLectureTime = ""; - if(lecture.getLectureTime() == 0){ + if (lecture.getLectureTime() == 0) { realLectureTime = "10:00 ~ 12:00"; - } else if(lecture.getLectureTime() == 1){ + } else if (lecture.getLectureTime() == 1) { realLectureTime = "13:00 ~ 14:50"; - } else if(lecture.getLectureTime() == 2){ + } else if (lecture.getLectureTime() == 2) { realLectureTime = "15:00 ~ 16:50"; - } else if(lecture.getLectureTime() == 3){ + } else if (lecture.getLectureTime() == 3) { realLectureTime = "17:00 ~ 19:00"; } @@ -69,32 +68,33 @@ public void showLectureList(){ /** * 해당 강의를 수강하는 학생 리스트를 보여주는 함수 + * * @param lectureId : 강의번호 */ public void showStudentListByLecture(String lectureId) throws IOException { - Optional findLecture = teacher.getLectureList().stream() .filter(lecture -> lecture.getLectureId().equals(lectureId)) .findFirst(); - if(findLecture.isEmpty()){ + if (findLecture.isEmpty()) { System.out.println("[해당아이디의 강의는 존재하지 않습니다.]"); System.out.println(); return; } List lectureRegistrationList = findLecture.get().getLectureRegistrationList(); - if(lectureRegistrationList.isEmpty()){ + if (lectureRegistrationList.isEmpty()) { System.out.println(" [해당 강의를 수강하고 있는 학생이 없습니다.] "); System.out.println(); return; } - for(LectureRegistration lectureRegistration: lectureRegistrationList){ + for (LectureRegistration lectureRegistration : lectureRegistrationList) { Student student = studentRepository.findById(lectureRegistration.getStudentId()); - System.out.println("학생명: "+student.getName()); + System.out.println("학생명: " + student.getName()); } } - public boolean isTeacherLectureListEmpty(){ + + public boolean isTeacherLectureListEmpty() { return teacher.getLectureIdList().isEmpty(); } } diff --git a/src/src/service/UserService.java b/src/src/service/UserService.java index 4d6fe5a..5680cd3 100644 --- a/src/src/service/UserService.java +++ b/src/src/service/UserService.java @@ -11,8 +11,8 @@ import java.util.ArrayList; public class UserService { - private Repository studentRepository; - private Repository teacherRepository; + private Repository studentRepository; + private Repository teacherRepository; private Admin admin; public UserService() throws IOException { @@ -20,12 +20,12 @@ public UserService() throws IOException { this.teacherRepository = RepositoryProvider.getInstance().provide(ServiceType.TEACHER); this.admin = Admin.getInstance(); } - public Student loginStudent(String id, String pw) throws IOException { + public Student loginStudent(String id, String pw) throws IOException { Student student = studentRepository.findById(id); - if(student!=null && student.getPassword().equals(pw)){ + if (student != null && student.getPassword().equals(pw)) { System.out.println(); - System.out.println("["+student.getName()+"]"+"학생님 로그인되셨습니다!"); + System.out.println("[" + student.getName() + "]" + "학생님 로그인되셨습니다!"); System.out.println(); return student; } @@ -33,20 +33,21 @@ public Student loginStudent(String id, String pw) throws IOException { return null; } + public Teacher loginTeacher(String id, String pw) throws IOException { Teacher teacher = teacherRepository.findById(id); - if(teacher!=null && teacher.getPassword().equals(pw)){ + if (teacher != null && teacher.getPassword().equals(pw)) { System.out.println(); - System.out.println("["+teacher.getName()+"]"+"강사님 로그인되셨습니다!"); + System.out.println("[" + teacher.getName() + "]" + "강사님 로그인되셨습니다!"); System.out.println(); return teacher; } System.out.println("[로그인정보가 일치하지 않아 메인메뉴로 돌아갑니다.]"); return null; - } - public Admin loginAdmin(String id, String pw){ - if(admin.getId().equals(id)&&admin.getPassword().equals(pw)){ + + public Admin loginAdmin(String id, String pw) { + if (admin.getId().equals(id) && admin.getPassword().equals(pw)) { System.out.println(); System.out.println("[관리자]님 로그인되셨습니다!"); System.out.println(); @@ -55,10 +56,12 @@ public Admin loginAdmin(String id, String pw){ System.out.println("[로그인정보가 일치하지 않아 메인메뉴로 돌아갑니다.]"); return null; } - public Object logout(){ + + public Object logout() { return null; } - public void signInStudent(String id, String password, String name, String gender, String phoneNumber, String birthday, String accountNumber, String accountPassword ) throws IOException { + + public void signInStudent(String id, String password, String name, String gender, String phoneNumber, String birthday, String accountNumber, String accountPassword) throws IOException { Student newStudent = Student.builder() .id(id) .password(password) @@ -75,6 +78,7 @@ public void signInStudent(String id, String password, String name, String gender studentRepository.insert(newStudent); studentRepository.save(); } + public void signInTeacher(String id, String password, String name, String gender, String phoneNumber, String birthday, String email) throws IOException { Teacher newTeacher = Teacher.builder() .id(id) @@ -91,10 +95,12 @@ public void signInTeacher(String id, String password, String name, String gender teacherRepository.save(); } - public boolean isExistStudent(String studentId){ + + public boolean isExistStudent(String studentId) { return studentRepository.isExist(studentId); } - public boolean isExistTeacher(String teacherId){ + + public boolean isExistTeacher(String teacherId) { return teacherRepository.isExist(teacherId); } }