package teamHW05;
import java.util.Scanner;
class Student1 {
int num;
String name;
int score;
Student1(int num, String name, int score) {
this.num = num;
this.name = name;
this.score = score;
System.out.println(num + "번 " + name + "학생이 저장되었습니다!");
}
void printList() {
System.out.println(num+"번 학생 "+" | "+ this.name + " [" + this.score + "점]");
}
void setScore(int score) {
this.score = score;
System.out.println( this.name + " 학생의 점수가 " + this.score + "점으로 업데이트 되었습니다!\n");
}
}
public class Assignment02 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
Student1[] data = new Student1[3];
String userMain = "=== 학생부 프로그램 ===\n"
+ "1. 학생목록 출력\n"
+ "2. 학생 1명 출력\n"
+ "3. 프로그램 종료\n"
+ "================\n "
+ "\n"
+ "번호 입력 : ";
String managerMain = "=== 관리자 모드 ===\n"
+ "1. 학생 생성\n"
+ "2. 학생 점수 변경\n"
+ "3. 관리자 모드 종료\n"
+ "4. 프로그램 종료\n"
+ "==============\n "
+ "\n"
+ "번호 입력 : ";
String name = "";
int score = 0;
int index = 0;
boolean flag = false;
while (true) {
System.out.println();
System.out.print(userMain);
int action = sc.nextInt();
if (action == 3) {
System.out.println("프로그램을 종료합니다...");
flag = true;
break;
}
else if (action == 1) {
if(index <= 0) {
System.out.println("저장된 학생이 없습니다!");
continue;
}
System.out.println("\n=== 학생부 목록 ===");
for (int i = 0; i < index; i++) {
data[i].printList();
}
System.out.println("===================");
}
else if (action == 2) {
if(index <= 0) {
System.out.println("저장된 학생이 없습니다!");
continue;
}
System.out.println("출력하고 싶은 학생의 번호를 입력하세요.");
System.out.print("번호 입력 : ");
int num = sc.nextInt();
if (num < 1 || num > index) {
System.out.println("해당 번호의 학생이 존재하지 않습니다!");
continue;
}
data[num - 1].printList();
}
else if (action == 1234) {
System.out.println("관리자 모드로 이동합니다.");
while (true) {
System.out.println();
System.out.print(managerMain);
action = sc.nextInt();
if (action == 3) {
System.out.println("관리자 모드를 종료하겠습니다.");
System.out.println("사용자 모드로 이동합니다.");
break;
}
else if (action == 1) {
if (index >= data.length) {
System.out.println("정원이 초과되었습니다.");
}
while (index < data.length) {
while (true) {
System.out.println((index + 1) + "번 학생의 이름을 입력해주세요.");
System.out.print("이름 입력 : ");
name = sc.next();
System.out.println("'"+ name + "' 학생을 등록하시겠습니까?");
System.out.println("1) 네 2) 아니오");
System.out.print("번호 입력 : ");
action = sc.nextInt();
if (action != 1) {
System.out.println("다시 입력해주세요!");
continue;
}
break;
}
while (true) {
System.out.println("'"+ name + "' 학생의 점수를 입력해주세요.");
System.out.print("점수 입력 : ");
score = sc.nextInt();
if (score < 0 || score > 100) {
System.out.println("0 ~ 100점으로 입력해주세요!");
continue;
}
break;
}
data[index++] = new Student1(index, name, score);
break;
}
}
else if (action == 2) {
if (index <= 0) {
System.out.println("저장된 학생이 없습니다!");
continue;
}
while(true) {
System.out.println("변경할 학생의 번호를 입력해주세요 : ");
int num = (sc.nextInt()) - 1;
if (num >= 0 && num < index) {
while (true) {
System.out.println("몇 점으로 수정하시겠습니까?");
System.out.print("점수 입력 : ");
score = sc.nextInt();
if (score > 100 || score < 0) {
System.out.println("0 ~ 100점으로 입력해주세요!");
continue;
}
else {
break;
}
}
data[num].setScore(score);
break;
}
else {
System.out.println("해당 번호의 학생이 존재하지 않습니다!");
System.out.println("다시 입력해주세요!");
continue;
}
}
}
else if(action == 4) {
System.out.println("프로그램을 종료합니다...");
flag = true;
break;
}
else {
System.out.println("잘못 입력하셨습니다!");
System.out.println("다시 입력해주세요!");
}
}
}
else {
System.out.println("잘못 입력하셨습니다!");
System.out.println("다시 입력해주세요!");
}
if(flag) {
break;
}
}
}
}