买票

 1 public class Demo {
 2     public static void main(String[] args) {
 3         //  需求:飞机票价格按照 头等舱、经济舱,月份,金额
 4         //  旺季(5-10)头等舱 9折,经济舱 8.5折。 淡季(11-4)头等舱 7折、经济舱 6.5折
 5         Scanner sc = new Scanner(System.in);
 6         System.out.println("请输入仓位类型:");
 7         String type = sc.next();
 8         System.out.println("请输入对应的月份:");
 9         int month = sc.nextInt();
10         System.out.println("请输入机票价格:");
11         double money = sc.nextDouble();
12 
13         double plane = plane(type, month, money);
14         System.out.println("当前的机票价格是:" + plane);
15 
16     }
17 
18     public static double plane(String type, int month, double money){
19 
20         //  判断月份是淡季还是旺季
21         if (month >= 5 && month <= 10){
22             //  旺季
23             switch (type){
24                 case "头等舱":
25                     money *= 0.9;
26                     break;
27                 case "经济舱":
28                     money *= 0.85;
29                     break;
30                 default:
31                     System.out.println("请选择正确的仓位...");
32                     money = -1;
33             }
34         }else if (month == 11 || month == 12 || month >= 1 && month <= 4){
35             //  淡季
36             switch (type){
37                 case "头等舱":
38                     money *= 0.7;
39                     break;
40                 case "经济舱":
41                     money *= 0.65;
42                     break;
43                 default:
44                     System.out.println("请选择正确的仓位...");
45                     money = -1;
46             }
47         }else {
48             System.out.println("请选择对应的月份...");
49         }
50 
51         return money;
52     }
53 }

 


public class Demo1 {
public static void main(String[] args) {
// 需求:飞机票价格按照 头等舱、经济舱,月份,金额
// 旺季(5-10)头等舱 9折,经济舱 8.5折。 淡季(11-4)头等舱 7折、经济舱 6.5
Scanner sc = new Scanner(System.in);
System.out.println("请输入仓位类型:");
String type = sc.next();
System.out.println("请输入对应的月份:");
int month = sc.nextInt();
System.out.println("请输入机票价格:");
double money = sc.nextDouble();

double plane = plane(type, month, money);
System.out.println("当前的机票价格是:" + plane);

}

public static double plane(String type, int month, double money){

// 判断月份是淡季还是旺季
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.7;
break;
case "经济舱":
money *= 0.65;
break;
default:
System.out.println("请选择正确的仓位...");
money = -1;
}
}else {
System.out.println("请选择对应的月份...");
}

return money;
}
}
posted @ 2024-01-19 15:18  小※兽  阅读(13)  评论(0)    收藏  举报