购买飞机票

题目:
机票价格按照淡季旺季,头等舱和经济舱收费,输入机票原价,月份和头等舱或经济舱
按照如下规则计算飞机票价格:旺季(5-10月),头等舱9折,经济舱8.5折,淡季(11月到来年4月)头等舱7折,经济舱6.5折。

代码:

public class yunsuan {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入机票原价:");
        double price = sc.nextDouble();
        System.out.println("请输入飞机票月份:");
        int month = sc.nextInt();
        System.out.println("请输入飞机票舱位(头等舱为1,经济舱为2):");
        int seat = sc.nextInt();

        double money = calc(price, month, seat);
        System.out.println("机票折后价为" + money);

    }


    public static double calc(double price, int month, int seat) {
        if(month <=0 ||month >=13){
            return -1;
        } else if (month >= 5 && month <= 10) {

            if (seat == 1) {
                price = price * 0.9;
            } else {
                price = price * 0.85;
            }


        } else if (month <= 5 || month >= 10 ) {

            if (seat == 1) {
                price = price * 0.7;
            } else {
                price = price * 0.69;
            }

        }
        return price;

    }

}

错误总结:
方法最后要有一个返回值,在整个方法的最后

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值