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;
}
}
'Programming Language > Java' 카테고리의 다른 글
[JAVA] HashSet (0) | 2020.09.18 |
---|---|
[JAVA] 어떤 숫자를 자릿수별로 배열에 저장하는 방법 (0) | 2020.08.07 |
[JAVA] 메모리 사용 영역(Runtime Data Area) (0) | 2020.07.02 |
[JAVA] 데이터타입 - 참조 타입 (0) | 2020.06.04 |
[JAVA] break문 사용 (0) | 2020.06.01 |