资讯动态

机票的计算

发布时间:2026/10/15 4:01:29 来源:尧图企业网站定制
package com.shang; import java.util.Scanner; public class AirTicket { static void main() { int x120;//燃油费 int y50;//建设费 Scanner sc new Scanner(System.in); System.out.println(请输入月份); int mouth sc.nextInt(); sc.nextLine(); System.out.println(请输入舱位类型); String cabin sc.nextLine(); System.out.println(请输入机票原价); double originalPrice sc.nextDouble(); double discount getDiscount(mouth,cabin); double finalPrice originalPrice*discount; System.out.printf(折扣:%.2f, 折后票价:%.2f\n,discount,finalPricexy); sc.close(); } public static double getDiscount(int mouth,String cabin){ //判断季节 boolean isPeak mouth5 mouth10; if (头等舱.equals(cabin)){ return isPeak ?0.9 :0.7; }else if (经济舱.equals(cabin)){ return isPeak ? 0.85 :0.65; }else { throw new IllegalArgumentException(舱位类型错误仅支持头等舱、经济舱); } } }

读完文章,也想定制专属网站?

尧图设计师 24 小时内与您沟通定制方案

免费获取报价 →
↑