public static void main(String[] args) {
//键盘输入
Scanner sc = new Scanner(System.in);
System.out.println("输入机票的原价");
double money = sc.nextDouble();
System.out.println("请输入机票类型");
String type = sc.next();
System.out.println("请选择月份");
int month = sc.nextInt();
//调用方法(输出调用)
System.out.println("机票现价是" + calc(money,type,month));
}
public static double calc(double money,String type,int month){
//判断用户选择的信息情况
if (month >=5 && month <=10){
//旺季
switch (type){
case"头等舱": money *= 0.9;
break;
case"经济舱": money *= 0.85;
break;
default:
System.out.println("没有您要的座位类型");
money = -1;
}
}else if (month == 11 || month == 12 || month >= 1 && month<=4){
switch (type){
case"头等舱": money *= 0.8;
break;
case"经济舱": money *= 0.75;
break;
default:
System.out.println("没有您要的座位类型");
money = -1;
}
}else{
System.out.println("对不起,您输入的月份有误");
return -1; //表示无法计算价格
}
return money;
}
java简单的买机票
猜你喜欢
转载自blog.csdn.net/qq_44765534/article/details/126694131
今日推荐
周排行