** 买机票问题:输入买的机票的出发月份,机票原价,机票类型 5-10月份头等舱打9折,经济舱打85折,11月到来年4月头等舱打7折,经济舱打65折 **
import java.util.Scanner;
public class Practice1 {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("请输入你所买机票的出发时间(月份):");
int time = scanner.nextInt();
if (time >= 13 || time <= 0) {
System.out.println("你的时间输入有误请重新输入...");
} else {
System.out.println("请输入你所买机票的原价:");
double price = scanner.nextDouble();
System.out.println("请输入你所买机票的类型(头等舱输入1,经济舱输入2):");
int type = scanner.nextInt();
switch (time) {
case 5:
case 6:
case 7:
case 8:
case 9:
case 10:
if (type == 1) {
System.out.println("你最终的机票价格为:" + price * 0.9);
} else if (type == 2) {
System.out.println("你最终的机票价格为:" + price * 0.85);
} else {
System.out.println("你的输入有误请重新输入...");
}
break;
case 11:
case 12:
case 1:
case 2:
case 3:
case 4:
if (type == 1) {
System.out.println("你最终的机票价格为:" + price * 0.7);
} else if (type == 2) {
System.out.println("你最终的机票价格为:" + price * 0.65);
} else {
System.out.println("你的输入有误请重新输入...");
}
break;
default:
System.out.println("你的输入有误请重新输入...");
}
}
}
}