diff --git a/src/src/Application.java b/src/src/Application.java index 6572d1b..60a64d5 100644 --- a/src/src/Application.java +++ b/src/src/Application.java @@ -1,13 +1,108 @@ package src; import src.domain.*; +import src.repository.Repository; +import src.repository.RepositoryProvider; import java.io.IOException; +import java.util.Queue; public class Application { public static void main(String[] args) throws IOException { + init(); AmsApp app = new AmsApp(); app.run(); } + public static void init() throws IOException { + Repository studentRepository = RepositoryProvider.getInstance().provide(ServiceType.STUDENT); + Repository lectureRepository = RepositoryProvider.getInstance().provide(ServiceType.LECTURE); + Repository lectureRegistrationRepository = RepositoryProvider.getInstance().provide(ServiceType.LECTUREREGISTRATION); + Repository teacherRepository = RepositoryProvider.getInstance().provide(ServiceType.TEACHER); + Repository, String> notificationRepository = RepositoryProvider.getInstance().provide(ServiceType.NOTIFICATION); + Lecture lecture1 = new Lecture("이것이 자바?1","이것이 자바?", 0,0,"현우진","hyeon123"); + lectureRepository.insert(lecture1); + Lecture lecture2 = new Lecture("저것도 자바?2","저것이 자바?", 1,1,"한석원","han123"); + lectureRepository.insert(lecture2); + Lecture lecture3 = new Lecture("요리조리 자바3","요리조리", 2,2,"현우진","hyeon123"); + lectureRepository.insert(lecture3); + + Teacher teacher1 = new Teacher("hyeon123","Hyeon123!!","현우진","male","010-5555-5555","1987-02-10","hyeon123@gmail.com"); + teacher1.getLectureIdList().add("이것이 자바?1"); + teacher1.getLectureIdList().add("요리조리 자바3"); + teacher1.getLectureList().add(lecture1); + teacher1.getLectureList().add(lecture3); + teacherRepository.insert(teacher1); + + teacherRepository.insert(teacher1); + Teacher teacher2 = new Teacher("han123","Han123!!","한석원","male","010-6666-6666","1964-11-07","han123@gmail.com"); + teacher2.getLectureIdList().add("저것도 자바?2"); + teacher2.getLectureList().add(lecture2); + teacherRepository.insert(teacher2); + + + + LectureRegistration lectureRegistration1 = new LectureRegistration(1L,"이것이 자바?1","kim123","월요일",0); + lectureRegistrationRepository.insert(lectureRegistration1); + LectureRegistration lectureRegistration2 = new LectureRegistration(2L,"요리조리 자바3","kim123","수요일",2); + lectureRegistrationRepository.insert(lectureRegistration2); + LectureRegistration lectureRegistration3 = new LectureRegistration(3L,"저것도 자바?2","koo123","화요일",1); + lectureRegistrationRepository.insert(lectureRegistration3); + LectureRegistration lectureRegistration4 = new LectureRegistration(4L,"요리조리 자바3","koo123","수요일",2); + lectureRegistrationRepository.insert(lectureRegistration4); + LectureRegistration lectureRegistration5 = new LectureRegistration(5L,"저것도 자바?2","jung123","화요일",1); + lectureRegistrationRepository.insert(lectureRegistration5); + LectureRegistration lectureRegistration6 = new LectureRegistration(6L,"요리조리 자바3","jung123","수요일",2); + lectureRegistrationRepository.insert(lectureRegistration6); + LectureRegistration lectureRegistration7 = new LectureRegistration(7L,"이것이 자바?1","kwon123","월요일",0); + lectureRegistrationRepository.insert(lectureRegistration7); + LectureRegistration lectureRegistration8 = new LectureRegistration(8L,"저것도 자바?2","kwon123","화요일",1); + lectureRegistrationRepository.insert(lectureRegistration8); + LectureRegistration lectureRegistration9 = new LectureRegistration(9L,"요리조리 자바3","jung123","수요일",2); + lectureRegistrationRepository.insert(lectureRegistration9); + + Student student1 = new Student("kim123","Kim123!!","김우재","male","010-1111-1111","1995-01-03","111-11-1","1234"); // 속성 채우기 + student1.getLectureRegistrationIdList().add(1L); + student1.getLectureRegistrationIdList().add(2L); + student1.getLectureRegistrationList().add(lectureRegistration1); + student1.getLectureRegistrationList().add(lectureRegistration2); + student1.setLectureCost(student1.getLectureCost()+200000L); + studentRepository.insert(student1); + + studentRepository.insert(student1); + Student student2 = new Student("koo123","Koo123!!","구태호","male","010-2222-2222","1999-12-10","222-22-2","1234"); // 속성 채우기 + student2.getLectureRegistrationIdList().add(3L); + student2.getLectureRegistrationIdList().add(4L); + student2.getLectureRegistrationList().add(lectureRegistration3); + student2.getLectureRegistrationList().add(lectureRegistration4); + student2.setLectureCost(student2.getLectureCost()+200000L); + studentRepository.insert(student2); + + + studentRepository.insert(student2); + Student student3 = new Student("jung123","Jung123!!","정혜미","female","010-3333-3333","1996-12-17","333-33-3","4321"); // 속성 채우기 + student3.getLectureRegistrationIdList().add(5L); + student3.getLectureRegistrationIdList().add(6L); + student3.getLectureRegistrationList().add(lectureRegistration5); + student3.getLectureRegistrationList().add(lectureRegistration6); + student3.setLectureCost(student3.getLectureCost()+200000L); + studentRepository.insert(student3); + + + studentRepository.insert(student3); + Student student4 = new Student("kwon123","Kwon123!!","권수현","female","010-4444-4444","1997-05-21","444-44-4","1234"); // 속성 채우기 + student4.getLectureRegistrationIdList().add(7L); + student4.getLectureRegistrationIdList().add(8L); + student4.getLectureRegistrationIdList().add(9L); + student4.getLectureRegistrationList().add(lectureRegistration7); + student4.getLectureRegistrationList().add(lectureRegistration8); + student4.getLectureRegistrationList().add(lectureRegistration9); + student4.setLectureCost(student4.getLectureCost()+300000L); + studentRepository.insert(student4); + + studentRepository.save(); + teacherRepository.save(); + lectureRepository.save(); + lectureRegistrationRepository.save(); + } } \ No newline at end of file diff --git a/src/src/domain/Admin.java b/src/src/domain/Admin.java index dbae826..1a0a11b 100644 --- a/src/src/domain/Admin.java +++ b/src/src/domain/Admin.java @@ -19,5 +19,4 @@ public static Admin getInstance(){ } return admin; } - } \ No newline at end of file diff --git a/src/src/domain/AmsApp.java b/src/src/domain/AmsApp.java index aa8e75a..4601ad2 100644 --- a/src/src/domain/AmsApp.java +++ b/src/src/domain/AmsApp.java @@ -70,14 +70,14 @@ public void run() throws IOException { if (num.equals("1")) { //수강신청 선택 studentService.showAllLectureList(); // 원하는 강의 고르기 - System.out.print("수강하고자 하는 강의의 강의 id를 입력해주세요: \n"); + System.out.print("수강하고자 하는 강의의 강의 ID를 입력해주세요: \n"); Constant.printInputText(); String choiceLectureId = scanner.nextLine(); studentService.registerLecture(choiceLectureId); } else if (num.equals("2")) { //수강신청 취소 if (studentService.showStudentAllRegistrationLecture()) { - System.out.println("취소하고자 하는 강의의 강의 id를 입력해주세요: \n"); + System.out.println("취소하고자 하는 강의의 강의 ID를 입력해주세요: \n"); Constant.printInputText(); String lectureId = scanner.nextLine(); studentService.deleteLecture(lectureId); @@ -164,6 +164,7 @@ public void run() throws IOException { System.out.print("[강의아이디를 입력해주세요]: "); String lectureId = scanner.nextLine(); System.out.println(); + teacherService.showStudentListByLecture(lectureId); break; } @@ -406,7 +407,7 @@ public void showDetailStudent() throws IOException { studentId = scanner.nextLine(); if(studentId.equals("0")) return; - System.out.println("**********************************"); + System.out.println("*********************************"); if (adminService.detailStudentInformation(studentId)) break; // 수정할 학생 찾음 } // 학생 찾아옴 @@ -531,7 +532,7 @@ public void showDetailTeacher() throws IOException { teacherId = scanner.nextLine(); if(teacherId.equals("0")) return; - System.out.println("*****************************************"); + System.out.println("*********************************"); if (adminService.detailTeacherInformation(teacherId)) System.out.println(); break; // 수정할 학생 찾음 diff --git a/src/src/domain/Bank.java b/src/src/domain/Bank.java index bfd7094..8ff9bde 100644 --- a/src/src/domain/Bank.java +++ b/src/src/domain/Bank.java @@ -12,9 +12,10 @@ public class Bank { static{ accountList = new ArrayList<>(); - accountList.add(new Account("111-11-1", "1111", 1000000L)); - accountList.add(new Account("222-22-2", "1111", 3000L)); - accountList.add(new Account("333-33-3", "0000", 10000L)); + accountList.add(new Account("111-11-1", "1234", 1000000L)); + accountList.add(new Account("222-22-2", "1234", 1000000L)); + accountList.add(new Account("333-33-3", "1234", 1000000L)); + accountList.add(new Account("444-44-4", "1234", 50000L)); } //결제승인체크(학생계좌번호, 계좌비밀번호 맞는지 체크) @@ -49,5 +50,17 @@ public long finalBalance(String accountNumber){ } return 0; } + + //효성은행에 존재하는 계좌인지 체크 + public boolean checkAmsAccount(String accountNumber){ + for (Account account : accountList) { + if(account.equals(accountNumber)){ + return true; + } + } + System.out.println("[효성Bank에 존재하는 계좌가 아닙니다!]"); + System.out.println(); + return false; + } } diff --git a/src/src/domain/LectureRegistration.java b/src/src/domain/LectureRegistration.java index eaf1dea..4302cc8 100644 --- a/src/src/domain/LectureRegistration.java +++ b/src/src/domain/LectureRegistration.java @@ -1,10 +1,14 @@ package src.domain; +import lombok.AllArgsConstructor; import lombok.Data; +import lombok.NoArgsConstructor; import java.io.Serializable; @Data +@AllArgsConstructor +@NoArgsConstructor public class LectureRegistration implements Serializable { //student - lecture의 중간 객체 private Long id; diff --git a/src/src/domain/Student.java b/src/src/domain/Student.java index dd9baa8..51802bf 100644 --- a/src/src/domain/Student.java +++ b/src/src/domain/Student.java @@ -36,6 +36,7 @@ public Student(String id, String password, String name, String gender, String ph this.accountPassword = accountPassword; this.lectureCost = 0L; this.lectureRegistrationIdList = new ArrayList<>(); + this.lectureRegistrationList = new ArrayList<>(); } //선택된 학생 수정할 수 있는 정보 출력 public void editStudentInformation(){ diff --git a/src/src/domain/Teacher.java b/src/src/domain/Teacher.java index 1ccb669..f9da5af 100644 --- a/src/src/domain/Teacher.java +++ b/src/src/domain/Teacher.java @@ -4,7 +4,9 @@ import lombok.Data; import lombok.NoArgsConstructor; +import javax.swing.plaf.synth.SynthRadioButtonMenuItemUI; import java.io.Serializable; +import java.util.ArrayList; import java.util.List; @Data @@ -22,6 +24,18 @@ public class Teacher implements Serializable { private transient List lectureList; private List lectureIdList; + public Teacher(String id, String password, String name, String gender, String phoneNumber, String birthday, String email){ + this.id = id; + this.password = password; + this.name = name; + this.gender = gender; + this.phoneNumber = phoneNumber; + this.birthday = birthday; + this.email = email; + this.lectureList = new ArrayList<>(); + this.lectureIdList = new ArrayList<>(); + } + //선택된 학생 수정할 수 있는 정보 출력 public void editTeacherInformation(){ System.out.println("------------[강사정보수정]------------"); diff --git a/src/src/service/AdminService.java b/src/src/service/AdminService.java index dd73075..ef88607 100644 --- a/src/src/service/AdminService.java +++ b/src/src/service/AdminService.java @@ -30,6 +30,7 @@ public class AdminService { private Admin admin; private LocalDate lastPaymentDay; + public AdminService() throws IOException { this.studentRepository = RepositoryProvider.getInstance().provide(ServiceType.STUDENT); this.teacherRepository = RepositoryProvider.getInstance().provide(ServiceType.TEACHER); @@ -44,6 +45,10 @@ public void setAdmin(Admin admin){ this.admin = admin; } + public boolean checkInAmsAccount(String accountNumber){ + return bank.checkAmsAccount(accountNumber); + } + //학원결제시스템 public void bankSystem() throws IOException { LocalDate nowDate = LocalDate.now(); @@ -62,6 +67,7 @@ public void bankSystem() throws IOException { for (Student student : studentList) { boolean checkAccount = bank.checkAccount(student.getAccountNumber(), student.getAccountPassword()); boolean paymentAccount = bank.paymentAccount(student.getAccountNumber(), student.getLectureCost()); + System.out.println(student.getLectureCost()); Long result = bank.finalBalance(student.getAccountNumber());//결제가 완료되고 남은 학생 잔액 String adminContent = ""; @@ -169,24 +175,28 @@ public void newEditStudentInformation(String studentId, int option, String value System.out.println("-------------------------------"); System.out.println("학생의 비밀번호 수정이 완료되었습니다!"); System.out.println("수정된 학생의 비밀번호: " + value); + studentRepository.save(); break; case 2: student.setName(value); System.out.println("----------------------------"); System.out.println("학생의 이름이 수정 완료되었습니다!"); System.out.println("수정된 학생의 이름: " + value); + studentRepository.save(); break; case 3: student.setPhoneNumber(value); System.out.println("--------------------------------"); System.out.println("학생의 휴대폰번호가 수정 완료되었습니다!"); System.out.println("수정된 학생의 휴대폰번호: " + value); + studentRepository.save(); break; case 4: student.setAccountPassword(value); System.out.println("----------------------------------"); System.out.println("학생의 계좌비밀번호가 수정 완료되었습니다!"); System.out.println("수정된 학생의 계좌비밀번호: " + value); + studentRepository.save(); break; } } @@ -236,21 +246,25 @@ public void newEditTeacherInformation(String teacherId, int option, String value teacher.setPassword(value); System.out.println("강사의 비밀번호 수정이 완료되었습니다."); System.out.println("수정된 강사의 비밀번호: " + value); + teacherRepository.save(); break; case 2: teacher.setName(value); System.out.println("강사의 이름이 수정 완료되었습니다."); System.out.println("수정된 강사의 이름: " + value); + teacherRepository.save(); break; case 3: teacher.setPhoneNumber(value); System.out.println("강사의 휴대폰번호가 수정 완료되었습니다."); System.out.println("수정된 강사의 휴대폰번호: " + value); + teacherRepository.save(); break; case 4: teacher.setEmail(value); System.out.println("강사의 이메일이 수정 완료되었습니다."); System.out.println("수정된 강사의 이메일: " + value); + teacherRepository.save(); break; } } diff --git a/src/src/service/StudentService.java b/src/src/service/StudentService.java index e1270b4..a15ae4d 100644 --- a/src/src/service/StudentService.java +++ b/src/src/service/StudentService.java @@ -130,8 +130,7 @@ String intLectureDayToRealDay (int lectureDay) { // 강의 시간 숫자를 실제 시간으로 바꿔주는 함수 // lectureTime을 숫자로 받으면 각 번호에 맞는 시간으로 리턴 - String intLectureTimeToRealTime (int lectureTime) { - if(lectureTime == 0){ + String intLectureTimeToRealTime (int lectureTime) {if(lectureTime == 0){ return "10:00 ~ 12:00"; } else if(lectureTime == 1){ return "13:00 ~ 14:50"; @@ -180,6 +179,7 @@ public void registerLecture(String choiceLectureId) throws IOException { studentRepository.save(); lectureRepository.save(); //studentRegistrations.put(student.getId(), lecture.getLectureRegistrationList()); + System.out.println(); System.out.println("수강 신청이 완료되었습니다.\n"); } else diff --git a/src/src/service/TeacherService.java b/src/src/service/TeacherService.java index c85978b..8dc8aed 100644 --- a/src/src/service/TeacherService.java +++ b/src/src/service/TeacherService.java @@ -9,6 +9,7 @@ import src.repository.RepositoryProvider; import java.io.IOException; +import java.sql.SQLOutput; import java.util.List; import java.util.Optional; @@ -16,7 +17,6 @@ public class TeacherService { private Teacher teacher; private Repository studentRepository; - public TeacherService() throws IOException { this.studentRepository = RepositoryProvider.getInstance().provide(ServiceType.STUDENT); } @@ -72,12 +72,18 @@ public void showLectureList(){ * @param lectureId : 강의번호 */ public void showStudentListByLecture(String lectureId) throws IOException { - Lecture findLecture = teacher.getLectureList().stream() + + Optional findLecture = teacher.getLectureList().stream() .filter(lecture -> lecture.getLectureId().equals(lectureId)) - .findFirst() - .get(); + .findFirst(); + + if(findLecture.isEmpty()){ + System.out.println("[해당아이디의 강의는 존재하지 않습니다.]"); + System.out.println(); + return; + } - List lectureRegistrationList = findLecture.getLectureRegistrationList(); + List lectureRegistrationList = findLecture.get().getLectureRegistrationList(); if(lectureRegistrationList.isEmpty()){ System.out.println(" [해당 강의를 수강하고 있는 학생이 없습니다.] "); System.out.println(); diff --git a/src/src/service/UserService.java b/src/src/service/UserService.java index 524bf55..4d6fe5a 100644 --- a/src/src/service/UserService.java +++ b/src/src/service/UserService.java @@ -24,6 +24,7 @@ public Student loginStudent(String id, String pw) throws IOException { Student student = studentRepository.findById(id); if(student!=null && student.getPassword().equals(pw)){ + System.out.println(); System.out.println("["+student.getName()+"]"+"학생님 로그인되셨습니다!"); System.out.println(); return student; @@ -35,6 +36,7 @@ public Student loginStudent(String id, String pw) throws IOException { public Teacher loginTeacher(String id, String pw) throws IOException { Teacher teacher = teacherRepository.findById(id); if(teacher!=null && teacher.getPassword().equals(pw)){ + System.out.println(); System.out.println("["+teacher.getName()+"]"+"강사님 로그인되셨습니다!"); System.out.println(); return teacher; @@ -45,6 +47,7 @@ public Teacher loginTeacher(String id, String pw) throws IOException { } 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(); return admin; @@ -53,7 +56,6 @@ public Admin loginAdmin(String id, String pw){ return null; } public Object logout(){ - System.out.println("[로그아웃이 완료되었습니다.]"); return null; } public void signInStudent(String id, String password, String name, String gender, String phoneNumber, String birthday, String accountNumber, String accountPassword ) throws IOException { diff --git a/src/src/util/Constant.java b/src/src/util/Constant.java index 5633a79..1eeed92 100644 --- a/src/src/util/Constant.java +++ b/src/src/util/Constant.java @@ -190,7 +190,8 @@ public static void incorrectNumber() { } public static void printLogout() { - System.out.println("[로그아웃] 되셨습니다!"); + System.out.println(); + System.out.println("[로그아웃이 완료되었습니다.]"); } public static void reInput() {