java使用switch编月份和舱位,java基础问题

给你一种if方式,如下:public class Test {

private boolean isHot=true;//是否旺季

private String siteType=null;//舱位类型

private double TD_hot_price=0;//旺季头等舱折扣

private double JJ_hot_price=0;//旺季经济舱折扣

private double TD_price=0;//淡季头等舱折扣

private double JJ_price=0;//淡季头等舱折扣

private double base=0;//原价

private List hotMonth=new ArrayList<>();

public static void main(String[] args){

String curr_month="09";//出行月份

String type="TD";//舱位

double money=0;//所需票价

Test t=new Test();

t.initData();//初始化数据

money= t.calMoney(curr_month,type);//计算

System.out.println(curr_month+"月份,"+(t.isHot?"旺季":"淡季")+",机票价格为:"+money);

}

/**

* 计算

* @param month 出行月份

* @param type 舱位类型

* @return 价格

*/

public double calMoney(String month,String type){

double money=0;

//判断所属淡季、旺季

if(hotMonth.contains(month)){

isHot=true;

}else{

isHot=false;

}

//

if(isHot){

//旺季+头等=base*0.9

if ("TD".equals(type)){

money=base*TD_hot_price;

}

else if ("JJ".equals(type)){

money=base*JJ_hot_price;

}

}else{

//淡季+头等=base*0.5

if ("TD".equals(type)){

money=base*TD_price;

}

else if ("JJ".equals(type)){

money=base*JJ_price;

}

}

return money;

}

/**

* 初始化数据

*/

public void initData(){

//

base=6000;//

siteType="TD";

TD_hot_price=0.9;

JJ_hot_price=0.8;

TD_price=0.5;

JJ_price=0.4;

//旺季

hotMonth.add("04");

hotMonth.add("05");

hotMonth.add("06");

hotMonth.add("07");

hotMonth.add("08");

hotMonth.add("09");

hotMonth.add("10");

}

}

温馨提示:答案为网友推荐,仅供参考

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值