要求:用户购买机票时,机票原价按照淡季,旺季,头等舱还是经济舱的情况进行优惠 。优惠方案如下:5-10月为旺季,头等舱9折,经济舱8.5折 ;11月-来年4月为淡季,头等舱7折,经济舱6.5折,计算出优惠后的价格
public class planeTicket {
public static void main(String[] args) {
double price=ticket(1000,11,"经济舱");
System.out.println("优惠后的价格是"+price);
}
public static double ticket(double price,int month,String type){
// 判断当前月份是淡季还是旺季
if(month>=5&&month<=10){
switch(type){
case"头等舱":price=price*0.9;
break;
case"经济舱":price=price*0.85;
break;
}
}else{
switch(type){
case"头等舱":price=price*0.7;
break;
case"经济舱":price=price*0.65;
break;
}
}
return price;
}
}