java飞机票打折问题

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

全部代码如下

package com.itbeiyou;

import java.util.Scanner;

public class Fly {
public static void main(String[] args) {
// 需求:机票价格按照淡季旺季、头等舱和经济舱收费、输入机票原价、月份和头等舱或经济舱。
// 按照如下规则计算机票价格:旺季(5-10月)头等舱9折,经济舱8.5折,淡季(11月到来年4月)头等舱7折,经济舱6.5折。
System.out.println("请输入飞机票原价");
Scanner sc=new Scanner(System.in);
int price=sc.nextInt();
System.out.println("请输入当前月份");
int month=sc.nextInt();
System.out.println("请输入仓位 0头等舱 1经济舱");
int cang=sc.nextInt();
//旺季
if(month>=5&&month<=10){
//仓位
if(cang==0){
price=(int)(price*0.9);
}else if(cang==1){
price=(int)(price*0.85);
}
//淡季
} else if ((month>=11&&month<=12)||(month>=1&&month<=4)) {
if(cang==0){
price=(int)(price*0.7);
} else if (cang==1) {
price=(int)(price*0.65);
}

}
System.out.println("打折后的票价是"+price);

}
}

结果图如下:

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

今天的接口写完了吗?

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值