7.text--判断数的存在
黑马 ---- 判断数的存在
卖飞机票
机票价格按照淡季旺季、头等舱和经济舱收费,输入机票原价、月份和头等舱和经济舱
规则:旺季(5-10月)头等舱 9 折、经济舱 8.5 折
淡季(11-4月)头等舱 7 折、经济舱 6.5 折
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
System.out.println("请输入原价:");
int price = s.nextInt();
System.out.println("请输入月份:");
int month = s.nextInt();
System.out.println("请输入位置:");
String seat = s.next();
System.out.println("您的新票价是:" + newPrice(price,month,seat));
s.close();
}
public static double newPrice(int price,int month,String seat){
double newPrice = 0;
if(month <= 10 && month >= 5){ //旺季
switch (seat){
case "头等舱":
newPrice = price * 0.9;
break;
case "经济舱":
newPrice = price * 0.85;
break;
default:
System.out.println("座位输入有误!");
break;
}
}else if(month == 11 || month == 12 || (month <= 4 && month >= 1)){ //淡季
switch (seat){
case "头等舱":
newPrice = price * 0.7;
break;
case "经济舱":
newPrice = price * 0.65;
break;
default:
System.out.println("座位输入有误!");
break;
}
}else{
System.out.println("月份输入有误!");
return newPrice;
}
return newPrice;
}