: 매일 저녁, 하루를 마무리하며 작성 !
: ⭕ 지식 위주, 학습한 것을 노트 정리한다고 생각하고 작성하면서 머리 속 흩어져있는 지식들을 정리 !
class Solution {
public int[] solution(long n) {
String x = String.valueOf(n);
int[] answer = new int[x.length()];
for (int i = 0; i < answer.length; i++) {
answer[i] = Integer.parseInt(x.substring(answer.length-1-i, answer.length-i));
}
return answer;
}
}
캠프 관리 프로그램
프로그램 역할 : 내배캠 스프링 수강생들을 관리하는 프로그램
캠프 관리 프로그램
섹션 1 + 2 통합 완료
// MKmain class
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;
public class MKmain {
static Scanner sc = new Scanner(System.in);
// Student 객체를 저장할 리스트
//static Student student;
private static ArrayList<Student> studentList = new ArrayList<>();
private static ArrayList<Subject> subjectList = new ArrayList<>();
private static int count = 3;
// 위에 카운트 3으로 해놓은 이유 : 임의로 가나다 라마바 넣어놔서 3으루 해놨어요 !
public static void main(String[] args) {
Student student1 = new Student(1, "가나다");
Student student2 = new Student(2, "라마바");
ArrayList<Subject> subjectList1 = new ArrayList<>();
ArrayList<Subject> subjectList2 = new ArrayList<>();
subjectList1.addAll(Arrays.stream(Subject.values()).toList());
subjectList2.addAll(Arrays.stream(Subject.values()).toList());
student1.SetSubjectList(subjectList1);
student2.SetSubjectList(subjectList2);
studentList.add(student1);
studentList.add(student2);
try {
displayMainView();
} catch (Exception e) {
System.out.println("\n오류 발생!\n프로그램을 종료합니다.");
}
}
private static void displayMainView() throws InterruptedException {
boolean flag = true;
while (flag) {
System.out.println("\n==================================");
System.out.println("내일배움캠프 수강생 관리 프로그램 실행 중...");
System.out.println("1. 수강생 관리");
System.out.println("2. 점수 관리"); // 구현 할 항목 @@@@@@@@@@@@
System.out.println("3. 프로그램 종료");
System.out.print("관리 항목을 선택하세요... ");
int input = sc.nextInt();
switch (input) {
case 1 -> displayStudentView(); // 수강생 관리 // 완료
case 2 -> displayScoreView(); // 점수 관리 // 구현 할 항목 @@@@@@@@@@@@
case 3 -> flag = false; // 프로그램 종료
default -> {
System.out.println("잘못된 입력입니다.\n되돌아갑니다!");
Thread.sleep(2000);
}
}
}
System.out.println("프로그램을 종료합니다.");
}
private static void displayStudentView() {
boolean flag = true;
while (flag) {
System.out.println("==================================");
System.out.println("수강생 관리 실행 중...");
System.out.println("1. 수강생 등록");
System.out.println("2. 수강생 목록 조회");
System.out.println("3. 메인 화면 이동");
System.out.print("관리 항목을 선택하세요...");
int input = sc.nextInt();
switch (input) {
case 1 -> createStudent(); // 수강생 등록
case 2 -> inquireStudent(); // 수강생 목록 조회
case 3 -> flag = false; // 메인 화면 이동
default -> {
System.out.println("잘못된 입력입니다.\n메인 화면 이동... ");
flag = false;
}
}
}
}
// 수강생 등록
private static void createStudent() {
System.out.println("\n수강생을 등록합니다...");
System.out.print("수강생 이름 입력: ");
String studentName = sc.next();
// 기능 구현 (필수 과목, 선택 과목)
String studentID = Integer.toString(count);
Student student = new Student(count, studentName);
count++;
studentList.add(student);
int requiredCount = 0; // 필수 과목 수 카운트
int optionalCount = 0; // 선택 과목 수 카운트
System.out.println("등록할 과목을 숫자로 선택해주세요. 'done'를 입력하면 과목 선택이 완료됩니다.");
System.out.println("필수과목: [ 1.JAVA | 2.OOP | 3.Spring | 4.JPA | 5.MySQL ]");
System.out.println("선택과목: [ 6.디자인패턴 | 7.Spring Security | 8.Redis | 9.MongoDB]");
while (true) {
String chooseSubject = sc.next();
if (chooseSubject.equals("done")) {
if (requiredCount < 3 || optionalCount < 2) {
// 최소 3개 이상의 필수 과목, 2개 이상의 선택 과목 필수 조건 확인
System.out.println("최소 3개 이상의 필수 과목, 2개 이상의 선택 과목을 선택합니다.");
continue;
} else {
break;
}
}
try {
boolean isUnique = true;
int subjectNumber = Integer.parseInt(chooseSubject);
// 중복 체크 메인으로 이동
for (int i = 0; i < subjectList.size(); i++) {
if (subjectList.get(i).GetSubjectId() == subjectNumber) {
isUnique = false;
}
}
if (isUnique) {
Subject subject = Subject.findByCode(subjectNumber);
System.out.println("subject = " + subject);
if (subject.GetisRequired()) {
requiredCount++;
} else {
optionalCount++;
}
// 함수 추가 안하고 과목 등록 처리
subjectList.add(subject);
} else {
System.out.println("이미 등록한 과목입니다.");
}
} catch (IllegalArgumentException e) {
System.out.println("유효한 과목을 선택하세요.");
}
}
student.SetSubjectList(subjectList);
System.out.println("수강생 정보:");
System.out.println("ID: " + student.GetStudentID());
System.out.println("이름: " + student.GetStudentName());
System.out.println("수강한 과목: " + student.GetSubjectList());
System.out.println("수강생 등록 성공!\n");
}
// 수강생 목록 조회
private static void inquireStudent() {
System.out.println("\n수강생 목록을 조회합니다...");
// 기능 구현
int index = 0;
for (Student student : studentList) {
if (index == 0) {
System.out.print("[ ");
}
System.out.print(student.GetStudentID() + "." + student.GetStudentName());
if (index != studentList.size() - 1) {
System.out.print(" | ");
} else {
System.out.println(" ]");
}
index++;
}
if (index == 0) {
System.out.println("등록되어 있는 수강생이 없습니다.");
} else {
System.out.println("\n수강생 목록 조회 성공!");
}
}
private static void displayScoreView() {// 구현 할 항목@@@@@@@@@@@
boolean flag = true;
while (flag) {
System.out.println("==================================");
System.out.println("점수 관리 실행 중...");
System.out.println("1. 수강생의 과목별 시험 회차 및 점수 등록"); // 구현 할 항목 @@@@@@@@@@@@
System.out.println("2. 수강생의 과목별 회차 점수 수정");
System.out.println("3. 수강생의 특정 과목 회차별 등급 조회");
System.out.println("4. 메인 화면 이동");
System.out.print("관리 항목을 선택하세요... ");
int input = sc.nextInt();
switch (input) {
case 1 -> {
createScore();
flag = false;
} // 수강생의 과목별 시험 회차 및 점수 등록 // 구현 할 항목@@@@@@@@@@@
case 2 -> updateRoundScoreBySubject(); // 수강생의 과목별 회차 점수 수정
case 3 -> inquireRoundGradeBySubject(); // 수강생의 특정 과목 회차별 등급 조회
case 4 -> flag = false; // 메인 화면 이동
default -> {
System.out.println("잘못된 입력입니다.\n메인 화면 이동...");
flag = false;
}
}
}
}
private static String getStudentId() { // 구현 중 @@@@@@@@@@@@
// 점수를 등록할 수강생을 선택해 주세요
if (!studentList.isEmpty()) {
System.out.print("\n관리할 수강생의 번호를 입력하시오...\n");
for (int i = 0; i < studentList.size(); i++) {
System.out.println("[ " + studentList.get(i).GetStudentID() + " : " + studentList.get(i).GetStudentName() + " ]");
}
} else {
System.out.println("등록되어 있는 수강생이 없습니다. \n");
// 등록된 수강생이 없을 경우 -1 반환
}
return String.valueOf(sc.nextInt() - 1);
}
// 수강생의 과목별 시험 회차 및 점수 등록
private static void createScore() { // 구현 중 @@@@@@@@@@@@
// 관리할 수강생 고유 번호
int studentId = Integer.parseInt(getStudentId());
int SubjectInput = 0;
int IndexInput = 0;
int ScoreInput = 0;
// 수강생이 등록한 과목들 출력해주기
if (!studentList.get(studentId).GetSubjectList().isEmpty()) {
System.out.println((studentId + 1) + "번 " + studentList.get(studentId).GetStudentName()
+ " 수강생의 점수를 등록할 과목을 선택해주세요. ( 번호 입력 )");
for (int i = 1; i <= studentList.get(studentId).GetSubjectList().size(); i++) {
System.out.println("[ " + i + " : " + studentList.get(studentId).GetSubjectList().get(i-1) + " ]");
}
} else {
System.out.println("해당 수강생은 등록되어 있는 과목이 없습니다. \n 메인으로 돌아갑니다.");
}
boolean validInput = false;
while (!validInput) {
// 과목 선택 입력
SubjectInput = sc.nextInt() - 1;
// 입력이 올바른지 확인
if (SubjectInput >= 0 && SubjectInput < studentList.get(studentId).GetSubjectList().size()) {
validInput = true; // 올바른 입력이면 반복 종료
} else {
// 잘못된 입력일 경우 사용자에게 다시 입력 요청
System.out.println("올바르지 않은 입력입니다. 다시 선택해주세요.");
}
}
System.out.println((studentId + 1) + "번 " + studentList.get(studentId).GetStudentName()
+ " 수강생의 점수를 등록할 과목 " + studentList.get(studentId).GetSubjectList().get(SubjectInput) + "의 회차를 선택해주세요.");
// 회차당 등록 미등록 여부 띄워주기
String[] strings = studentList.get(studentId).getExamResultOrUnregistered(SubjectInput);
System.out.println(Arrays.toString(strings));
validInput = false;
while (!validInput) {
// 회차 선택 입력
IndexInput = sc.nextInt() - 1;
// 이미 점수가 등록된 회차인지 확인
if (IndexInput >= 0 && IndexInput < strings.length && strings[IndexInput].equals("미등록")) {
validInput = true; // 올바른 입력이면 반복 종료
} else {
// 이미 점수가 등록된 회차를 선택한 경우 다시 입력 요청
System.out.println("이미 점수가 등록된 회차입니다. 다시 선택해주세요.");
}
}
System.out.println((studentId + 1) + "번 " + studentList.get(studentId).GetStudentName()
+ " 수강생의 점수를 등록할 과목 " + studentList.get(studentId).GetSubjectList().get(SubjectInput) + "의 " + (IndexInput + 1) + " 회차 점수를 입력해주세요.");
validInput = false;
while (!validInput) {
// 점수 입력
ScoreInput = sc.nextInt();
// 입력이 올바른 범위에 속하는지 확인
if (ScoreInput >= 0 && ScoreInput <= 100) {
validInput = true; // 올바른 입력이면 반복 종료
} else {
// 올바르지 않은 범위의 점수를 입력한 경우 다시 입력 요청
System.out.println("점수는 0에서 100 사이의 값을 입력해주세요.");
}
}
// 점수 등록(과목index, 회차index, 점수)
studentList.get(studentId).registerExamScore(SubjectInput, IndexInput, ScoreInput);
// 미등록, 등록 재갱신
strings = studentList.get(studentId).getExamResultOrUnregistered(SubjectInput);
// 점수 등록 후 출력
System.out.println("\n점수 등록 성공!");
System.out.println(Arrays.toString(strings));
// 회차당 등록 미등록 여부 띄워주기
strings = studentList.get(studentId).getExamRankOrUnregistered(SubjectInput, IndexInput);
System.out.println(Arrays.toString(strings));
}
// 수강생의 과목별 회차 점수 수정
private static void updateRoundScoreBySubject() {
String studentId = getStudentId(); // 관리할 수강생 고유 번호
// 기능 구현 (수정할 과목 및 회차, 점수)
System.out.println("시험 점수를 수정합니다...");
// 기능 구현
System.out.println("\n점수 수정 성공!");
}
// 수강생의 특정 과목 회차별 등급 조회
private static void inquireRoundGradeBySubject() {
String studentId = getStudentId(); // 관리할 수강생 고유 번호
// 기능 구현 (조회할 특정 과목)
System.out.println("회차별 등급을 조회합니다...");
// 기능 구현
System.out.println("\n등급 조회 성공!");
}
}