Programming Language/Java
[JAVA] Airline Booking Engine
BS Kwak
2020. 7. 12. 19:24
BASIC REQUIREMENT
Newyork : 7 million miles Manila: 4 million miles London:12 million miles
The price is
• 5 million miles or less: 1 million won
• 8 million miles or less: 1.5 million won
• Over 10 million miles: 2 million won
Peak Season: May 1st through July 31st, the peak season price is added by 500,000 won from the existing price.
Implement the limitation that each ticket can only be purchased for two tickets at a time because there are many bookings.
Enter the above data in an array, and enter the city and departure date when you run the program so that the price is printed.
import java.util.Scanner;
public class Flight {
public static void main(String[] args) {
String m; String des; // 사용자가 입력할 출발일 (월:m), 도착지(des)
int cost = 0; int Ticket=0; // 사용자가 지불할 가격(cost), 티켓의 개수(Ticket)
Scanner scanner = new Scanner(System.in);
String Month[]= {"May","June","July"}; //성수기에 해당하는 달
//출발일 입력
System.out.println("출발일을 입력하세요");
String StartDay = scanner.nextLine();
int index = StartDay.indexOf("/");
m = StartDay.substring(index+1);
//구매할 티켓의 개수 입력
System.out.println("몇장의 티켓을 구매하겠습니까?");
Ticket = scanner.nextInt();
while (Ticket>2){
System.out.println("티켓이 없습니다. 2명 이하로 다시입력하세요.");
Ticket=scanner.nextInt();
}
scanner.nextLine();
//도착지 입력
System.out.println("도착지를 입력하세요.");
des=scanner.nextLine();
//가격 계산
for (int i=0;i<3;i++) {
if (m.equals(Month[i])) { //성수기일때 가격
cost=CityCost(des)+500000;
break;
}
else cost=CityCost(des); //비수기 일때 가격
}
System.out.println("성공적으로 티켓을 구매하셨습니다. 가격은"+cost*Ticket+"입니다.");
scanner.close();
}
public static int CityCost(String des) { //도시 별 가격
String City[]= {"Newyork","Manila","London"};
int Ocost=0;
if(des.equals(City[0])) Ocost=1500000;
else if (des.equals(City[1])) Ocost=1000000;
else Ocost=2000000;
return Ocost;
}
}