买飞机票(Java案例)

需求:

用户购买机票时,机票原价会按照淡季、旺季、头等舱还是经济舱的情况进行相应的优惠,优惠方案如下:
5~10月为旺季,头等舱9折,经济舱8.5折;11月到来年4月为淡季,头等舱7折,经济舱6.5折,请开发程序计算出用户当前机票的优惠价格。
public class test {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        System.out.println("请输入机票价格:");
        int price = sc.nextInt();

        System.out.println("请输入月份:");
        int month = sc.nextInt();

        System.out.println("请选择头等舱or经济舱");
        String sit = sc.next();

        //判断当前是旺季还是淡季
        if (month >= 5 && month <= 10){
            //旺季
            switch (sit){
                case "头等舱":
                    System.out.println("头等舱九折:" + price * 0.9);
                    break;
                case "经济舱":
                    System.out.println("经济舱八点五折:" + price * 0.85);
                    break;
            }
        }else{
            //淡季
            switch (sit){
                case "头等舱":
                    System.out.println("头等舱七折:" + price * 0.7);
                    break;
                case "经济舱":
                    System.out.println("经济舱六点五折:" + price * 0.65);
                    break;
            }
        }
    }

}

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
根据提供的引用内容,可以看出Java飞机机票的价格是根据淡季和旺季来确定的。具体的实现方式可能需要进一步的代码或者说明。以下是一个简单的例子来演示如何根据淡季和旺季来确定机票价格: ```java import java.util.Scanner; public class TicketPrice { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); System.out.print("请输入机票原价:"); double originalPrice = scanner.nextDouble(); System.out.print("请输入月份(1-12):"); int month = scanner.nextInt(); System.out.print("请输入舱位类型(头等舱/经济舱):"); String cabinType = scanner.next(); double finalPrice = 0; if (month >= 4 && month <= 10) { // 旺季 if (cabinType.equals("头等舱")) { finalPrice = originalPrice * 1.5; } else if (cabinType.equals("经济舱")) { finalPrice = originalPrice * 1.2; } } else { // 淡季 if (cabinType.equals("头等舱")) { finalPrice = originalPrice * 1.3; } else if (cabinType.equals("经济舱")) { finalPrice = originalPrice * 1.1; } } System.out.println("机票最终价格为:" + finalPrice); } } ``` 这个例子中,用户需要输入机票的原价、月份和舱位类型,然后根据输入的信息来计算机票的最终价格。如果月份在4-10之间,则为旺季,头等舱价格为原价的1.5倍,经济舱价格为原价的1.2倍;如果月份不在4-10之间,则为淡季,头等舱价格为原价的1.3倍,经济舱价格为原价的1.1倍。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值