使用js打出html页面

根据出行的月份和仓位的类型,核算机票最终的价格。

(1)在5月~10月出行,如果仓位是头等舱,则机票打9折;如果仓位是经济舱,则机票打7.5折。

(2)在其他的月份出行,如果仓位是头等舱,则机票打6折;如果仓位是经济舱,则机票打3折

 var getPrice=function(month,postion){
  if(month=>5&&month<=10){
   if(postion=="头等舱"){
        return 0.9;
     }else if(postion=="经济舱"){
         return 0.75
     }
  }else{
  if(postion =="头等舱"){
      return 0.6
    }else{
      return 0.3
    }
 }
}

这个是获取折扣的方法,传入月份和位置两个参数


import java.util.Scanner;

public class buy_ticket {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        System.out.println("请输入您购买机票的月份 : ");
        int month = sc.nextInt();

        System.out.println("请输入您购买机票的价格 : ");
        double money = sc.nextDouble();

        System.out.println("请输入您购买机票的类型(头等舱或经济舱) : ");
        String type = sc.next();

        double finish_ticket = buy_ticket1(month, type, money);

        System.out.println("您购买的机票经优惠为" + finish_ticket + "元");
    }

    public static double buy_ticket1(int month, String type, double money) {
        double finish_ticket = 0.0;

        if (month >= 5 && month <= 10) { //旺季
            if (type.equals("头等舱")) finish_ticket = money * 0.9; //头等舱9else if (type.equals("经济舱")) finish_ticket = money * 0.85; //经济舱85折
        } else if ((month >= 1 && month <= 4) || month == 11 || month == 12) { //淡季
            if (type.equals("头等舱")) finish_ticket = money * 0.7; //头等舱7else if (type.equals("经济舱")) finish_ticket = money * 0.65; //经济舱65折
        }
        return finish_ticket;
    }
}