计算飞机票

1. 计算飞机票

jichag

我的代码:

package com.zhang;

import java.util.Scanner;

/*
* 用户购买机票*/
public class Test1 {
    public static void main(String[] args) {
        //
        Scanner sc = new Scanner(System.in);

        System.out.println("请输入出行月份:");
        int month = sc.nextInt();
        System.out.println("头等舱输入1,经济仓输入2:");
        int level = sc.nextInt();
        System.out.println("请输入机票原价:");
        double fee = sc.nextInt();

        int rs = price(month,level,fee);
    }
    public static int price(int month,int level,double fee){
        double rs = 0;
        switch (month){
            case 5:
            case 6:
            case 7:
            case 8:
            case 9:
            case 10:
                if(level == 1){
                    rs =fee * 0.9;
                }else{
                    rs =fee * 0.85;
                }
                break;
            case 11:
            case 12:
            case 1:
            case 2:
            case 3:
            case 4:
                if(level == 1){
                    rs =fee * 0.9;
                }else{
                    rs =fee * 0.85;
                }
                break;
        }
        int rs2 = (int)rs;
        System.out.println("您的机票价格为:"+rs);
        return rs2;
    }
}

运行结果:
在这里插入图片描述

老师的代码

在这里插入图片描述

生成验证码

在这里插入图片描述

  • 6
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 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、付费专栏及课程。

余额充值