import java.io.*;
public class Jeju{
/* 2차배열 표==================
* 항공 숙박 관광 렌트카 option
16만 7만 5만 7만 option_price
* 0or99 0or1 0or1 0or1 option_boolean
*=============================
* 이름-name
* 연락처-phone_number
* 패키지내역- 항공권은 무조건 사야함
* 여행일자-period
* 인원(항공료에만반영)-num_people
*/
String option[]={"항공권","숙박","관광","렌트카"};
BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
int option_price[]={160000,70000,50000,70000};
int option_boolean[]={1,0,0,0};
String name,phone_number; //이름,전화번호
int period,num_people,inputed_option;//기간,인원수,입력된옵션번호,총금액
String yesorno;
//잘못된 입력값을 걸러준다.////////////////////
int readlineProcess(String a,int arraylength) throws IOException{
int b=0;
if(a.equals("n")){return 999; // n 값을 입력받으면 다음으로 넘어감
}else{b=Integer.parseInt(a);
if (b>0&&b<arraylength+1){return b;
}else{System.out.println("장난치면 시베리아로 휴가간다");
return 99;}
}
}
void greet() throws IOException{
System.out.println("여행 사이트 예약 프로그램");
System.out.println("== 옵션 목록 ==");
System.out.println("항공권(왕복) 160000원");
for(int i=1;i<option.length;i++){
System.out.printf("%s(1일) %d원\n",option[i],option_price[i]);
}
}
void inputOption() throws IOException{
System.out.println("==== 선택하신 옵션 =====");
for(int i=0;i<option_price.length;++i){ // 선택된 옵션이 있으면 보여줌
if(option_boolean[i]%2==1){ // option_boolean 이 홀수면 보여줌
System.out.print(option[i]+"\t");}
}
System.out.println("\n=====================");
System.out.println("옵션을 선택해 주세요.");
System.out.println("추가/삭제 1.항공권(불가) 2.숙박 3.관광 4.렌트카 n.입력완료");
inputed_option=readlineProcess(in.readLine(),option.length);
if (inputed_option==1){System.out.println("배타고 갈거냐?");inputed_option--;}// 항공권은 추가삭제 불가
if(inputed_option!=999||inputed_option==1){ //n값을 받아 readlineProcess반환값이 999가 아니거나 1이면 루프
for(int i=0;i<option_price.length;++i){
if(i==inputed_option-1){option_boolean[i]++;} // 짝수or 홀수로 만듦
}
inputOption();}//루프
}
void inputDetail() throws IOException{
System.out.println("귀하의 성함을 입력해 주세요");
name=in.readLine();
System.out.println("전화번호를 입력해 주세요");
phone_number=in.readLine();
phonenumProcess();
System.out.println("여행하실 기간을 입력해 주세요(최대10일)");
period=readlineProcess(in.readLine(),10);
System.out.println("몇 명이서 가실거심??(4인까지 가능)");
num_people=readlineProcess(in.readLine(),4);
}
void phonenumProcess()throws IOException{
String ptemp[]=new String[2];
StringBuffer sb=new StringBuffer();
StringBuffer sb2=new StringBuffer();
String temp[]=phone_number.split(" "); //011 1111 1111 형식의 전화번호를 나눔
if(temp.length>1){ //나눠졌을 때
for(int i=0;i<temp.length;i++){
sb.append(temp[i]);if(i<temp.length-1)sb.append("-"); // 나눠진 배열+ "-" + 다음배열....
}
phone_number=sb.toString();
}//if
String temp2[]=phone_number.split("-"); // -가 있는 형식이면 그냥 내보내려함
if(temp2.length<2&&phone_number.length()>9){ // 나눠진 배열이 2보다 작으면 -가 없는것이므로 진행
ptemp[0]=phone_number.substring(phone_number.length()-4); // 끝네자리
System.out.println(ptemp[0]+" "+phone_number.length());
switch(phone_number.length()-4){
case 7:ptemp[1]=phone_number.substring(phone_number.length()-8,phone_number.length()-4);break; // 남은자리수가 7이면 중간자리 4개잘라냄
case 6:ptemp[1]=phone_number.substring(phone_number.length()-7,phone_number.length()-4);break;
default:ptemp[1]="false"; // 형식을 모르겠으면 그냥 출력
}
if (!ptemp[1].equals("false")){ // 형식을 모르겠으면 그냥 출력
sb2.append(phone_number.substring(0,3)); //붙이기
sb2.append("-");
sb2.append(ptemp[1]);
sb2.append("-");
sb2.append(ptemp[0]);
phone_number=sb2.toString();
}
}
}
void result(){
System.out.println("=="+ name +"님 께서 입력하신 내용 ==");
System.out.println("===== 옵션 =====");
for(int i=0;i<option_price.length;++i){ // 선택된 옵션이 있으면 보여줌
if(option_boolean[i]%2==1){ // option_boolean 이 홀수면 보여줌
System.out.println(option[i]);}
}
System.out.println("====================\n전화번호\t"+phone_number+"\n여행기간\t"+period+"\n인원수\t"+num_people);
////////// 총 금액 계산 /////////////
int price_total=0; // 재시작할 때 초기화 하기 귀찮으므로 여기다 선언
for(int i=1;i<option.length;i++){ //선택되어진 옵션의 금액만 더한다.
if(option_boolean[i]%2==1){price_total+=option_price[i];}
}
price_total*=period; // 선택된 옵션금액에 여행기간을 곱한다.
price_total+=num_people*160000; //위에 인원수*항공권값을 더한다.
/////////////////////////////////////
System.out.println("결제하실 금액: "+price_total+" 원");
}
void callOrDie() throws IOException{
System.out.println("처음부터 다시할거에요?(Y) 아니면 끝내고 입금할거에요?(N)");
yesorno=in.readLine();
if(yesorno.equals("n")||yesorno.equals("N")){System.out.println("돈 빨리 입금하시고 안녕히가세요.");
}else{if(yesorno.equals("y")||yesorno.equals("Y"))
{loop();
}else{System.out.println("똑바로 입력해라");callOrDie();}
}
}
void loop() throws IOException{
inputOption();
inputDetail();
result();
callOrDie();
}
public static void main(String[] args) throws IOException{
Jeju a=new Jeju();
a.greet();
a.loop();
}
}
// 내장메서드 될 수 있는한 사용말래서 개고생


댓글 (1)