永发信息网

java编程。订购机票,机票的价格受到季节旺季。淡季影响,而且头等藏跟经济舱的价格也不一同。

答案:3  悬赏:70  手机版
解决时间 2021-03-16 18:43
假设机票原价为5000元,4-10月为旺季.旺季头等舱打9折 经济舱打八折 淡季头等舱打5这 经济舱打4折 编写程序 用IF选择结构 根据出行的月份和选择的舱位输出实际的机票价格。
最佳答案
public class Ticket {
  private int month;
  private int classLevel; //1: 头等舱, 2: 经济舱
  private int price;
  private int basePrice = 5000; //原价

  public Ticket(int month, int classLevel) {
  this.month = month;
  this.classLevel = classLevel;
  }

  public void showMeThePrice() {
  //旺季月份: 4-10
  if ((month >= 4) && (month <= 10)) {
  if (classLevel == 1) {
  price = basePrice * 0.9;
  System.out.println("Month: " + month + "; Class: " + classLevel + "; Price: " + price);
  } else if (classLevel == 2) {
  price = basePrice * 0.8;
  System.out.println("Month: " + month + "; Class: " + classLevel + "; Price: " + price);
  }
  }

  // 淡季月份: 1,2,3,11,12
  if ((month >= 1) && (month <= 3) || month = 11 || month = 12) {
  if (classLevel == 1) {
  price = basePrice * 0.5;
  System.out.println("Month: " + month + "; Class: " + classLevel + "; Price: " + price);
  } else if (classLevel == 2) {
  price = basePrice * 0.4;
  System.out.println("Month: " + month + "; Class: " + classLevel + "; Price: " + price);
  }
  }
  }
  }

  测试类:
  public class Test {
  Ticket myTicket = new Ticket(4, 1); //例如:四月,头等舱
  myTicket.showMeThePrice();//输出显示价格
  ...
  }

  以上代码全部手打,因为公司没有安装jdk,所以无法测试,你自己调试吧。
全部回答
int i =4; if i =<10 { 语句 } else { 语句 }
public double getfirstclassprice(double baseprice) { return ismidseason() ? baseprice * 0.9 : baseprice * 0.5; } public double gettouristclassprice(double baseprice) { return ismidseason() ? baseprice * 0.8 : baseprice * 0.4; } private boolean ismidseason() { int month = calendar.getinstance().get(calendar.month) + 1; return month >= 4 && month <= 10; } 上面那个好看些。看了下你的要求,貌似不太符合- -。 重写了个 public double getprice(double baseprice, int month, boolean isfirstclass) { double result; if (month >= 4 && month <= 10) { if (isfirstclass) { result = baseprice * 0.9; } else { result = baseprice * 0.8; } } else { if (isfirstclass) { result = baseprice * 0.5; } else { result = baseprice * 0.4; } } return result; }
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
老酒肴水饺地址在什么地方,想过去办事
王者荣耀安琪拉皮肤魔法小厨娘的活动是什么时
单选题He_________inanotherwayafterhewor
电动机工作效率如何计算
我要从深圳做火车去山东省龙口请问怎样才能又
汽车尾气污染应对大家提出哪些意见?
马蹄营菜市场地址在什么地方,想过去办事
一个小童星,不知道是哪个国家和名字,有图
上海华新装饰本溪有分公司吗?地址在哪??
小狗被大狗咬伤应该怎么处理
坐飞机遇上空难怎么办?
谷歌地球不显示地名
为什么LTE的同一个基站的两个小区切换失败
上海浦江镇附近有游泳馆吗
枸杞能和勃荠一起煲汤吗?
推荐资讯
仙剑4打到求仙山那里 应该是多少级
田字的笔顺怎么写
苹果手机D开头的手机代表什,
头皮上的是什么
去找人化妆遮胎记多少钱一次?
“Reading"是哪个城市?
安徽颍上喝酒划拳怎么样算赢,怎么划的啊
公司员工户外活动策划、好玩的趣味游戏策划?
欧麦娅在什么地方啊,我要过去处理事情
江山市新塘边川年小学这个地址在什么地方,我
香蕉冰箱里放过变黑了还能吃么
老妹20岁生日,送什么礼物比较有意义
正方形一边上任一点到这个正方形两条对角线的
阴历怎么看 ?