import
java.util.ArrayList;
import
java.util.Scanner;
public
class
CustomerManager3 {
static
ArrayList<Customer> custList =
new
ArrayList<>();
static
int
index = -
1
;
static
Scanner scan =
new
Scanner(System.in);
public
static
void
main(String[] args) {
while
(
true
) {
System.out.printf(
"\n[INFO] 고객 수 : %d, 인덱스 : %d\n"
, custList.size(), index);
System.out.println(
"메뉴를 입력하세요."
);
System.out.println(
"(I)nsert, (P)revious, (N)ext, "
+
"(C)urrent, (U)pdate, (D)elete, (Q)uit"
);
System.out.print(
"메뉴 입력: "
);
String menu = scan.next();
menu = menu.toLowerCase();
switch
(menu.charAt(
0
)) {
case
'i'
:
System.out.println(
"고객정보 입력을 시작합니다."
);
insertCustomerData();
System.out.println(
"고객정보를 저장했습니다."
);
break
;
case
'p'
:
System.out.println(
"이전 데이터를 출력합니다."
);
if
(index <=
0
) {
System.out.println(
"이전 데이터가 존재하지 않습니다."
);
}
else
{
index--;
printCustomerData();
}
case
'n'
:
System.out.println(
"다음 데이터를 출력합니다."
);
if
(index >= custList.size()-
1
) {
System.out.println(
"다음 데이터가 존재하지 않습니다."
);
}
else
{
index++;
printCustomerData();
}
break
;
case
'c'
:
System.out.println(
"현재 데이터를 출력합니다."
);
if
( (index >=
0
) && (index < custList.size())) {
printCustomerData();
}
else
{
System.out.println(
"출력할 데이터가 선택되지 않았습니다."
);
}
break
;
case
'u'
:
System.out.println(
"데이터를 수정합니다."
);
if
( (index >=
0
) && (index < custList.size())) {
System.out.println(index +
"번째 데이터를 수정합니다."
);
updateCustomerData();
}
else
{
System.out.println(
"수정할 데이터가 선택되지 않았습니다."
);
}
break
;
case
'd'
:
System.out.println(
"데이터를 삭제합니다."
);
if
( (index >=
0
) && (index < custList.size())) {
System.out.println(index +
"번째 데이터를 삭제합니다."
);
deleteCustomerData();
}
else
{
System.out.println(
"삭제할 데이터가 선택되지 않았습니다."
);
}
break
;
case
'q'
:
System.out.println(
"프로그램을 종료합니다."
);
scan.close();
System.exit(
0
);
break
;
default
:
System.out.println(
"메뉴를 잘 못 입력했습니다."
);
}
}
}
public
static
void
insertCustomerData() {
System.out.print(
"이름 : "
);
String name = scan.next();
System.out.print(
"성별(M/F) : "
);
char
gender = scan.next().charAt(
0
);
System.out.print(
"이메일 : "
);
String email = scan.next();
System.out.print(
"출생년도 : "
);
int
birthYear = scan.nextInt();
Customer customer =
new
Customer();
customer.setName(name);
customer.setGender(gender);
customer.setEmail(email);
customer.setBirthYear(birthYear);
custList.add(customer);
}
public
static
void
printCustomerData() {
System.out.println(
"==========CUSTOMER INFO================"
);
Customer customer = custList.get(index);
System.out.println(
"이름 : "
+ customer.getName());
System.out.println(
"성별 : "
+ customer.getGender());
System.out.println(
"이메일 : "
+ customer.getEmail());
System.out.println(
"출생년도 : "
+ customer.getBirthYear());
System.out.println(
"======================================="
);
}
public
static
void
deleteCustomerData() {
custList.remove(index);
}
public
static
void
updateCustomerData() {
Customer customer = custList.get(index);
System.out.println(
"---------UPDATE CUSTOMER INFO----------"
);
System.out.print(
"이름("
+ customer.getName() +
") :"
);
customer.setName(scan.next());
System.out.print(
"성별("
+ customer.getGender() +
") :"
);
customer.setGender(scan.next().charAt(
0
));
System.out.print(
"이메일("
+ customer.getEmail() +
") :"
);
customer.setEmail(scan.next());
System.out.print(
"출생년도("
+ customer.getBirthYear() +
") :"
);
customer.setBirthYear(scan.nextInt());
}
}