13강_영화관 무인예매기 (실생활예제)
import javax.swing.JOptionPane;
public class CGV {
public static void main(String[] args) {
String helloMsg="♥어서오세요 CGV입니다♥\n";
String menuMsg="1.예매하기\n2.음식 구매하기\n3.포인트 조회\n4.나가기\n";
String ageMsg="[청소년 구매 불가 상품]\n나이를 입력하세요\n";
String films="1.라이온킹(8:00)\n2.스파이더맨(12:00)\n3.사일런스(23:00)[청소년 관람 불가]\n4.뒤로가기\n";
String foods="1.팝콘 10000원\n2.콜라 3000원\n3.맥주 3000원\n4.뒤로가기\n";
int choice=0;
int age=0;
int money=1_000_000_000;
int point=0;
int t_price=10000;
int f_price=0;
int popcorn=10000;
int cola=3000;
int beer=3000;
boolean t_check;
boolean f_check;
while(true) {
t_check=true;
f_check=true;
choice=Integer.parseInt(JOptionPane.showInputDialog(helloMsg+menuMsg));
if(choice==4) break;
//잘못 입력했을 때 continue
if(!(choice>=1 &&choice<=3)) continue;
switch(choice) {
//예매하기 영역
case 1:
if(money - t_price <0) {
JOptionPane.showMessageDialog(null,"잔액이 부족합니다.");
continue;
}
//변수의 재사용
choice = Integer.parseInt(JOptionPane.showInputDialog(films));
if(choice==1) {
JOptionPane.showConfirmDialog(null,"라이온킹 예매 완료(8:00)");
}else if(choice==2) {
JOptionPane.showConfirmDialog(null,"스파이더맨 예매 완료(12:00).");
}else if(choice==3) {
age=Integer.parseInt(JOptionPane.showInputDialog(ageMsg));
if(age>19) {
JOptionPane.showConfirmDialog(null,"사일런스 예매 완료(23:00");
}else {
JOptionPane.showMessageDialog(null, "다시 시도해주세요");
t_check=false;
}
}else {
t_check=false;
JOptionPane.showConfirmDialog(null,"메인 메뉴로 이동합니다.");
continue;
}
//예매 완료일때
if(t_check) {
if(point>0 ) {
if(point-t_price>=0) {
point-=t_price;
}else {//포인트가 부족할 때
money -= (t_price - point);
point=0;
}
}else {//돈으로만 결제했을때
money-=t_price;
point += (int)(t_price * 0.5);
}
JOptionPane.showMessageDialog(null,"현재잔액:"+money+"원");
}
break;
//구매하기 영역
case 2:
//변수의 재사용
choice = Integer.parseInt(JOptionPane.showInputDialog(foods));
if(choice==1) {
if(money - popcorn <0) {
JOptionPane.showMessageDialog(null,"잔액이 부족합니다.");
continue;
}
JOptionPane.showConfirmDialog(null,"팝콘 구매완료");
f_price = popcorn;
}else if(choice==2) {
if(money - cola<0) {
JOptionPane.showMessageDialog(null,"잔액이 부족합니다.");
continue;
}
JOptionPane.showConfirmDialog(null,"콜라 구매완료");
f_price=cola;
}else if(choice==3) {
age=Integer.parseInt(JOptionPane.showInputDialog(ageMsg));
if(age>19) {
JOptionPane.showConfirmDialog(null,"맥주 구매완료");
f_price=beer;
}else {
JOptionPane.showMessageDialog(null, "다시 시도해주세요");
f_check=false;
}
}else {
f_check=false;
JOptionPane.showConfirmDialog(null,"메인 메뉴로 이동합니다.");
continue;
}
//구매 완료일때
if(f_check) {
if(point>0 ) {
if(point-f_price>=0) {
point-=f_price;
}else {//포인트가 부족할 때
money -= (f_price - point);
point=0;
}
}else {//돈으로만 결제했을때
money-=f_price;
point += (int)(f_price * 0.5);
}
JOptionPane.showMessageDialog(null,"현재잔액:"+money+"원");
}
break;
//포인트 조회 영역
case 3:
JOptionPane.showMessageDialog(null, "잔여포인트: "+point+"점");
break;
}
}
}}






