本文主要是介绍java飞机票打折问题,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
需求:机票价格按照淡季旺季、头等舱和经济舱收费、输入机票原价、月份和头等舱或经济舱。
// 按照如下规则计算机票价格:旺季(5-10月)头等舱9折,经济舱8.5折,淡季(11月到来年4月)头等舱7折,经济舱6.5折。
全部代码如下
package com.itbeiyou;import java.util.Scanner;public class Fly {
public static void main(String[] args) {
// 需求:机票价格按照淡季旺季、头等舱和经济舱收费、输入机票原价、月份和头等舱或经济舱。
// 按照如下规则计算机票价格:旺季(5-10月)头等舱9折,经济舱8.5折,淡季(11月到来年4月)头等舱7折,经济舱6.5折。
System.out.println("请输入飞机票原价");
Scanner sc=new Scanner(System.in);
int price=sc.nextInt();
System.out.println("请输入当前月份");
int month=sc.nextInt();
System.out.println("请输入仓位 0头等舱 1经济舱");
int cang=sc.nextInt();
//旺季
if(month>=5&&month<=10){
//仓位
if(cang==0){
price=(int)(price*0.9);
}else if(cang==1){
price=(int)(price*0.85);
}
//淡季
} else if ((month>=11&&month<=12)||(month>=1&&month<=4)) {
if(cang==0){
price=(int)(price*0.7);
} else if (cang==1) {
price=(int)(price*0.65);
}}
System.out.println("打折后的票价是"+price);}
}
结果图如下:
这篇关于java飞机票打折问题的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!