☰
机票的计算
2026/10/15 4:01:28 网站建设 项目流程
package com.shang; import java.util.Scanner; public class AirTicket { static void main() { int x=120;//燃油费 int y=50;//建设费 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,finalPrice+x+y); sc.close(); } public static double getDiscount(int mouth,String cabin){ //判断季节 boolean isPeak = mouth>=5 && mouth<=10; if ("头等舱".equals(cabin)){ return isPeak ?0.9 :0.7; }else if ("经济舱".equals(cabin)){ return isPeak ? 0.85 :0.65; }else { throw new IllegalArgumentException("舱位类型错误,仅支持头等舱、经济舱"); } } }

需要专业的网站建设服务?

联系我们获取免费的网站建设咨询和方案报价,让我们帮助您实现业务目标

立即咨询