题目:机票价格按照淡季旺季头等舱经济舱收费。
要求:输入机票原价,月份和舱位类型。
机票最终价格计算如下:
![](https://i-blog.csdnimg.cn/blog_migrate/43f46fca749bbe618b004c3b2c162e05.png)
public static void main(String[] args) {
Scanner sc = new Scanner(System.in); //三种输入用三种不同类型的变量来接收然后放在方法中。
System.out.println("请输入机票原价:");
double money = sc.nextDouble();
System.out.println("请输入月份:");
int month = sc.nextInt();
System.out.println("请输入舱位类型:");
String type = sc.next();
System.out.println("您的机票价格是:" + sale(money, month, type));
}
public static double sale(double a,int b,String c){
double sale = a;
if( 5 < b && b < 10 ){
switch(c){
case "头等舱":
sale = 0.9*a;
break;
case "经济舱":
sale = 0.85*a;
}
}else{
switch(c){
case "头等舱":
sale = 0.7*a;
break;
case "经济舱":
sale = 0.65*a;
}
}
return sale;
}
结果为:
![](https://i-blog.csdnimg.cn/blog_migrate/6e01165ce91e908920df172c13e26c4b.png)