1. 회원정보 보기 및 회원정보 수정(showSeat_modify)부분
이 콘솔프로그램을 이용하는 회원들의 정보를 관리하기 위해서 매니저가 필요하다. 그래서 이 부분을 만들었다.
1)
이 정보들을 보거나 수정하기 위해 manager의 비밀번호가 일치하는지 판단하도록 했다.
매니저 이외의 사람들이 마음대로 회원 정보를 보거나 수정할 수 없도록 하기 위해서다.
1.1)
회원정보를 보고 싶은 경우와 회원 정보를 수정하기 위해서 case 1,2로 나눴다.
case 1
회원 정보와 자리를 볼 수 있다. 회원가입만하고 로그인을 하지 않는 회원들은 자리가 row=0, col =0으로 뜨게 했다.
(아직 자리를 선택하지 않았으므로)
case 2회원 정보를 수정할 수 있다. 첫 번째 회원의 아이디를 수정할 경우, 두 번째 회원의 비밀번호를 수정할 경우로 나눴다.
-id을 수정할 경우 correct_id_pw(ID)
-pw를 수정할 경우 correct_id_pw(ID,PW)
이때, 코드가 너무 길어져서 다른 class로 회원을 수정할 수 있도록 나눴다.
(stack은 manager의 비밀번호를 5번 틀렸을 때를 가정해서 만들었다. 아직은 미완성이므로 주석처리를 했다.)
public class showSeat_modify {
//static int stack = 0;
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String Manager_password = "1234";
System.out.println("관리자 비밀번호를 입력하세요.");
String mPassword = sc.next();
if (Manager_password.equals(mPassword)){
System.out.println("1. 등록학생 보기");
System.out.println("2. 등록학생 수정");
int choice = sc.nextInt();
switch (choice){
case 1:
for (int i = 0; i < Seat_Assign.idx; i++) {
System.out.println(i + 1);
System.out.println("아이디 : " + Student_insert.AI_Students[i].getId());
System.out.println("비밀번호 : " + Student_insert.AI_Students[i].getPw());
System.out.println("현재 사용 중인 캐비닛은 " + Student_insert.AI_Students[i].getSeat_ROW()+"행 "+ Student_insert.AI_Students[i].getSeat_COL()+"열 입니다.");}
break;
case 2:
System.out.println("1. 아이디 수정");
System.out.println("2. 비밀번호 수정");
int choice2 = sc.nextInt();
if (choice2 ==1){
System.out.println(" 아이디을 입력해주세요");
String ID = sc.next();
new correct_id_pw(ID);}
else if (choice2 ==2) {
System.out.println(" 아이디을 입력해주세요");
String ID = sc.next();
System.out.println(" 비밀번호을 입력해주세요");
String PW = sc.next();
new correct_id_pw(ID,PW);}
else System.out.println("다시 입력해주세요1");
break;
default:
System.out.println("다시 입력해주세요2");
break;}
}else {
System.out.println("비밀번호가 틀렸습니다");
//stack++;
//if(stack ==5){
// System.out.println("5번 이상 틀리셨습니다.,관리");
//}
}
}
}
2)
id를 수정할 경우 첫 번째 correct_id_pw(String id)로 들어가고 pw를 수정할 경우 두 번째 correct_id_pw(String id)로 들어간다. 이때도 이미 가입된 아이디가 있는 경우를 생각해서 코드를 만들어봤다. (비밀번호는 중복 가능)
class correct_id_pw{
Scanner sc = new Scanner(System.in);
boolean id_pw_equal = false;
int log_in_overlap = -1;
boolean isDuplicate = false;
public correct_id_pw(String id){
for (int i = 0; i < Seat_Assign.idx; i++) {
if (Student_insert.AI_Students[i].getId().equals(id)) {
id_pw_equal = true;
log_in_overlap =i;
break;
}
}
if (log_in_overlap == -1) {
System.out.println("일치하는 아이디가 없습니다.");
}else{
System.out.println("새로운 아이디를 입력해주세요");
String newID = sc.next();
if(newID.length()==8){
for (int i = 0; i < Seat_Assign.idx; i++) {
if (Student_insert.AI_Students[i].getId().equals(newID)) {
isDuplicate = true;
break;
}
}
if (isDuplicate) { //아이디 중복 방지
System.out.println("중복된 아이디입니다.");
} else {
System.out.println("변경되었습니다.");
Student_insert.AI_Students[log_in_overlap].setID(newID);}
}else System.out.println("아이디 8자리를 입력해주세요");
}
}
public correct_id_pw(String id, String pw){
for (int i = 0; i < Seat_Assign.idx; i++) {
if (Student_insert.AI_Students[i].getId().equals(id) && Student_insert.AI_Students[i].getPw().equals(pw)) {
id_pw_equal = true;
log_in_overlap =i;
break;
}
}
if (log_in_overlap == -1) {
System.out.println("일치하는 정보가 없습니다.");
}else{
System.out.println("새로운 비밀번호를 입력해주세요");
String newPW = sc.next();
if (newPW.length()==6){
Student_insert.AI_Students[log_in_overlap].setPW(newPW);
System.out.println("변경되었습니다.");
}else System.out.println("비밀번호 6자리를 입력해주세요");
}
}
}
전체코드
2.회원정보 보기 및 회원정보 수정
import java.util.Scanner;
class correct_id_pw{
Scanner sc = new Scanner(System.in);
boolean id_pw_equal = false;
int log_in_overlap = -1;
boolean isDuplicate = false;
public correct_id_pw(String id){
for (int i = 0; i < Seat_Assign.idx; i++) {
if (Student_insert.AI_Students[i].getId().equals(id)) {
id_pw_equal = true;
log_in_overlap =i;
break;
}
}
if (log_in_overlap == -1) {
System.out.println("일치하는 아이디가 없습니다.");
}else{
System.out.println("새로운 아이디를 입력해주세요");
String newID = sc.next();
if(newID.length()==8){
for (int i = 0; i < Seat_Assign.idx; i++) {
if (Student_insert.AI_Students[i].getId().equals(newID)) {
isDuplicate = true;
break;
}
}
if (isDuplicate) { //아이디 중복 방지
System.out.println("중복된 아이디입니다.");
} else {
System.out.println("변경되었습니다.");
Student_insert.AI_Students[log_in_overlap].setID(newID);}
}else System.out.println("아이디 8자리를 입력해주세요");
}
}
public correct_id_pw(String id, String pw){
for (int i = 0; i < Seat_Assign.idx; i++) {
if (Student_insert.AI_Students[i].getId().equals(id) && Student_insert.AI_Students[i].getPw().equals(pw)) {
id_pw_equal = true;
log_in_overlap =i;
break;
}
}
if (log_in_overlap == -1) {
System.out.println("일치하는 정보가 없습니다.");
}else{
System.out.println("새로운 비밀번호를 입력해주세요");
String newPW = sc.next();
if (newPW.length()==6){
Student_insert.AI_Students[log_in_overlap].setPW(newPW);
System.out.println("변경되었습니다.");
}else System.out.println("비밀번호 6자리를 입력해주세요");
}
}
}
public class showSeat_modify {
//static int stack = 0;
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String Manager_password = "1234";
System.out.println("관리자 비밀번호를 입력하세요.");
String mPassword = sc.next();
if (Manager_password.equals(mPassword)){
System.out.println("1. 등록학생 보기");
System.out.println("2. 등록학생 수정");
int choice = sc.nextInt();
switch (choice){
case 1:
for (int i = 0; i < Seat_Assign.idx; i++) {
System.out.println(i + 1);
System.out.println("아이디 : " + Student_insert.AI_Students[i].getId());
System.out.println("비밀번호 : " + Student_insert.AI_Students[i].getPw());
System.out.println("현재 사용 중인 캐비닛은 " + Student_insert.AI_Students[i].getSeat_ROW()+"행 "+ Student_insert.AI_Students[i].getSeat_COL()+"열 입니다.");}
break;
case 2:
System.out.println("1. 아이디 수정");
System.out.println("2. 비밀번호 수정");
int choice2 = sc.nextInt();
if (choice2 ==1){
System.out.println(" 아이디을 입력해주세요");
String ID = sc.next();
new correct_id_pw(ID);}
else if (choice2 ==2) {
System.out.println(" 아이디을 입력해주세요");
String ID = sc.next();
System.out.println(" 비밀번호을 입력해주세요");
String PW = sc.next();
new correct_id_pw(ID,PW);}
else System.out.println("다시 입력해주세요1");
break;
default:
System.out.println("다시 입력해주세요2");
break;}
}else {
System.out.println("비밀번호가 틀렸습니다");
//stack++;
//if(stack ==5){
// System.out.println("5번 이상 틀리셨습니다.,관리");
//}
}
}
}
'언어 > Java' 카테고리의 다른 글
[JAVA] 간단한 캐비닛 Swing프로그램 (0) | 2023.07.05 |
---|---|
[JAVA] 간단한 캐비닛 콘솔프로그램(6) - AI_Student_Info 회원정보 저장 (0) | 2023.07.04 |
[JAVA] 간단한 캐비닛 콘솔프로그램(4) - Seat_Assign (0) | 2023.07.04 |
[JAVA] 간단한 캐비닛 콘솔프로그램(3) - Log_Out (0) | 2023.07.04 |
[JAVA] 간단한 캐비닛 콘솔프로그램(2) - Log_in (0) | 2023.07.04 |