![](https://img-blog.csdnimg.cn/direct/c0f07c9fb7184372bb6e35c6ea03cae9.png)
package com.homework;
public class Text {
public static void main(String[] args) {
//原价、月份、仓位仓位由0,1表示
buyAPlaneTicket(356,7,0);
}
public static double buyAPlaneTicket(double Price,int month,int Positions){
double Price1=0;
if (month>=5 && month <=10){
switch (Positions) {
case 0 -> {
System.out.println("您的头等舱优惠票价为:" + Price * 0.9);
Price1= Price * 0.9;
}
case 1 -> {
System.out.println("您的经济舱优惠票价为:" + Price * 0.85);
Price1= Price * 0.85;
}
}
} else if (month<=12 && month>=11) {
switch (Positions) {
case 0 -> {
System.out.println("您的头等舱优惠票价为:" + Price * 0.7);
Price1= Price * 0.7;
}
case 1 -> {
System.out.println("您的经济舱优惠票价为:" + Price * 0.65);
Price1= Price * 0.65;
}
}
} else if (month>=1 && month<=4) {
switch (Positions) {
case 0 -> {
System.out.println("您的头等舱优惠票价为:" + Price * 0.7);
Price1= Price * 0.7;
}
case 1 -> {
System.out.println("您的经济舱优惠票价为:" + Price * 0.65);
Price1= Price * 0.65;
}
}
}
return Price1;
}
}