/*
* 机票的价格按照淡季、旺季、头等舱、经济舱收费
* 输入机票原价、月份、头等舱或经济舱
* 旺季:5-10月 头等舱9折 经济舱8.5折
* 淡季:11-4月 头等舱7折 经济舱6.5折
* */
package com.dzt;
import java.util.Scanner;
public class 买机票 {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("请输入机票原价:");
double price = scanner.nextInt();
System.out.println("输入月份:");
int mon = scanner.nextInt();
System.out.println("输入舱位(头等舱/经济舱):");
String type = scanner.next();
double v = jiPiao(price, mon, type);
System.out.println("机票价格是"+v);
}
public static double jiPiao(double money, int mon, String type) {
if (mon >= 5 && mon <= 10) {
switch(type) {
case "经济舱":
money*=0.85;
break;
case "头等舱":
money*=0.9;
break;
default:
System.out.println("舱位有误!");
money=-1;
}
} else if (mon == 11 || mon == 12 && mon >= 1 || mon <= 4) {
switch(type) {
case "经济舱":
money*=0.65;
break;
case "头等舱":
money*=0.7;
break;
default:
System.out.println("舱位有误!");
money=-1;
}
} else {
System.out.println("输入正确的月份!");
}
return money;
}
}