package project;
import java.util.ArrayList;
import java.util.Scanner;
public class MainBoard {
public static void main(String[] args) {
ArrayList<Customer> al = new ArrayList<>();
Scanner sc = new Scanner(System.in);
boolean flag = true;
while(flag) {
System.out.println("===========================");
System.out.println("|1.등록 | 2.검색 | 3.수정 | 4.삭제 | 5.목록 | 6. 전체삭제 | 0. 종료");
System.out.print("입력: ");
int input = sc.nextInt();
switch(input) {
case 1:
int count = al.size() + 1;
System.out.print("이름:");
Scanner in = new Scanner(System.in);
String name = in.nextLine();
System.out.print("나이:");
int age = sc.nextInt();
Customer customer = new Customer(name, age, count);
al.add(customer);
break;
case 2:
System.out.print("검색할 이름을 쓰시오:");
int count2 = 0;
Scanner in2 = new Scanner(System.in);
String name2 = in2.nextLine();
for(int i = 0 ; i < al.size(); i++) {
if(name2.equals(al.get(i).getName())) {
System.out.println(al.get(i));
count2++;
}
}if(count2 == 0) {
System.out.println("그런사람은 없습니다");
}
break;
case 3:
System.out.println("전체목록");
for(int i = 0 ; i< al.size(); i++) {
System.out.println(al.get(i));
}
System.out.print("수정할 자료의 번호를 입력하세요");
Scanner sc2 = new Scanner(System.in);
int choose = sc2.nextInt();
System.out.println(al.get(choose-1));
System.out.println("1.이름수정 | 2. 나이 수정");
int select = sc2.nextInt();
switch(select) {
case 1: System.out.print("수정할 이름을 적으세요");
Scanner sc3 = new Scanner(System.in);
String name3 = sc3.nextLine();
al.get(choose-1).setName(name3);
break;
case 2:
System.out.print("수정할 나이을 적으세요");
Scanner nt = new Scanner(System.in);
int age3 = nt.nextInt();
al.get(choose-1).setAge(age3);
// 삭제시 목록 count 초기화
for(int i = choose-1; i < al.size(); i++ ) {
al.get(choose-1).setCount(i);
}
break;
}
System.out.println("수정완료");
break;
case 4:
System.out.println("전체목록");
for(int i = 0 ; i< al.size(); i++) {
System.out.println(al.get(i));
}
if(al.size() == 0) {
System.out.println("삭제할 자료가없습니다");
break;
}else {
System.out.println("삭제할 번호 입력");
int choose2 = sc.nextInt();
al.remove(choose2-1);
System.out.println("삭제완료!");
for(int i = choose2-1; i <al.size(); i++ ) {
al.get(i).setCount(i+1);
}
break;
}
case 5:
for(int i = 0 ; i< al.size(); i++) {
System.out.println(al.get(i));
}
break;
case 6:
al.clear();
break;
case 0:
flag = false;
break;
default:
System.out.println("잘못입력하셧습니다");
}
}
}
}
처음 클론코딩없이 만든거라 부족한 부분이 보였다.