需求:机票价格按照淡季旺季、头等舱和经济舱收费、输入机票原价、月份和头等舱或经济舱。机票最终优惠价格的计算方案如下:旺季(5-10月)头等5折,经济舱6折,淡季(11月到来年4月)头等舱8折,经济舱9折。
import java.util.Scanner;//扫描仪
public class java {
public static void main(String[] args) {
System.out.println("请输入购买机票的月份:");
Scanner a = new Scanner(System.in);
int a1 = a.nextInt();
System.out.println("请输入购买机票的价格:");
Scanner b = new Scanner(System.in);
int b1 = b.nextInt();
System.out.println("请输入购买机票的型号:");
Scanner c = new Scanner(System.in);
String c1 = c.next();
num(a1, b1, c1);
}
public static void num(int a, int b, String c) {
if (a >= 5 && a <= 10) {
switch (c) {
case "头等舱":
b *= 0.5;
System.out.println("打5折后价格为:" + b);
break;
case "经济舱":
b *= 0.6;
System.out.println("打6折后价格为:" + b);
break;
default:
System.out.println("输入错误");
}
} else if (a >= 0 && a <= 4 || a >= 11 && a <= 12) {
switch (c) {
case "头等舱":
b *= 0.8;
System.out.println("打8折后价格为:" + b);
break;
case "经济舱":
b *= 0.9;
System.out.println("打9折后价格为:" + b);
break;
default:
System.out.println("输入错误");
}
} else {
System.out.println("输入月份错误,请重新输入。");
}
}
}