Skip to content

Commit

Permalink
Merge pull request #47 from hamings/feature/koo
Browse files Browse the repository at this point in the history
#46 [refactor] 데이터 init() 및 출력문 수정 및 오류수정
  • Loading branch information
Koo-Tae-Ho authored Mar 27, 2024
2 parents c830323 + e23a3bd commit e735b19
Show file tree
Hide file tree
Showing 12 changed files with 167 additions and 17 deletions.
95 changes: 95 additions & 0 deletions src/src/Application.java
Original file line number Diff line number Diff line change
@@ -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<Student, String> studentRepository = RepositoryProvider.getInstance().provide(ServiceType.STUDENT);
Repository<Lecture, String> lectureRepository = RepositoryProvider.getInstance().provide(ServiceType.LECTURE);
Repository<LectureRegistration, Long> lectureRegistrationRepository = RepositoryProvider.getInstance().provide(ServiceType.LECTUREREGISTRATION);
Repository<Teacher, String> teacherRepository = RepositoryProvider.getInstance().provide(ServiceType.TEACHER);
Repository<Queue<Notification>, 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","[email protected]");
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","[email protected]");
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();
}
}
1 change: 0 additions & 1 deletion src/src/domain/Admin.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,4 @@ public static Admin getInstance(){
}
return admin;
}

}
9 changes: 5 additions & 4 deletions src/src/domain/AmsApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -164,6 +164,7 @@ public void run() throws IOException {
System.out.print("[강의아이디를 입력해주세요]: ");
String lectureId = scanner.nextLine();
System.out.println();

teacherService.showStudentListByLecture(lectureId);
break;
}
Expand Down Expand Up @@ -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; // 수정할 학생 찾음
} // 학생 찾아옴
Expand Down Expand Up @@ -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; // 수정할 학생 찾음
Expand Down
19 changes: 16 additions & 3 deletions src/src/domain/Bank.java
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}

//결제승인체크(학생계좌번호, 계좌비밀번호 맞는지 체크)
Expand Down Expand Up @@ -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;
}
}

4 changes: 4 additions & 0 deletions src/src/domain/LectureRegistration.java
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
1 change: 1 addition & 0 deletions src/src/domain/Student.java
Original file line number Diff line number Diff line change
Expand Up @@ -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(){
Expand Down
14 changes: 14 additions & 0 deletions src/src/domain/Teacher.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -22,6 +24,18 @@ public class Teacher implements Serializable {
private transient List<Lecture> lectureList;
private List<String> 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("------------[강사정보수정]------------");
Expand Down
14 changes: 14 additions & 0 deletions src/src/service/AdminService.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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();
Expand All @@ -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 = "";
Expand Down Expand Up @@ -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;
}
}
Expand Down Expand Up @@ -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;
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/src/service/StudentService.java
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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
Expand Down
16 changes: 11 additions & 5 deletions src/src/service/TeacherService.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@
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<Student,String> studentRepository;


public TeacherService() throws IOException {
this.studentRepository = RepositoryProvider.getInstance().provide(ServiceType.STUDENT);
}
Expand Down Expand Up @@ -72,12 +72,18 @@ public void showLectureList(){
* @param lectureId : 강의번호
*/
public void showStudentListByLecture(String lectureId) throws IOException {
Lecture findLecture = teacher.getLectureList().stream()

Optional<Lecture> findLecture = teacher.getLectureList().stream()
.filter(lecture -> lecture.getLectureId().equals(lectureId))
.findFirst()
.get();
.findFirst();

if(findLecture.isEmpty()){
System.out.println("[해당아이디의 강의는 존재하지 않습니다.]");
System.out.println();
return;
}

List<LectureRegistration> lectureRegistrationList = findLecture.getLectureRegistrationList();
List<LectureRegistration> lectureRegistrationList = findLecture.get().getLectureRegistrationList();
if(lectureRegistrationList.isEmpty()){
System.out.println(" [해당 강의를 수강하고 있는 학생이 없습니다.] ");
System.out.println();
Expand Down
Loading

0 comments on commit e735b19

Please sign in to comment.