给你一种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");
}
}
温馨提示:答案为网友推荐,仅供参考