今天给大家带来一期买飞机票的教程
工具:IDEA.JDK1.8
package jingji;
import java.util.Scanner;
public class test {
public static void main(String[] args) {
// 1.键盘录入机票原价
Scanner sc = new Scanner(System.in);
System.out.println("请输入当前的原价");
int ticket = sc.nextInt();
System.out.println("请输入当前的月份");
int month =sc.nextInt();
System.out.println("请输入当前购买的舱位 0 头等仓 1经济舱");
int seat = sc.nextInt();
// 判断月份是旺季还是淡季
if(month >=5 && month <=10){
if(seat == 0){
//头等舱
ticket = (int)(ticket * 0.9);
} else if (seat == 1) {
//经济舱
ticket = (int)(ticket * 8.5);
}else{
System.out.println("没有这个舱位");
}
//旺季
} else if ((month >= 1&&month <= 4) || (month >= 11 && month <= 12)) {
//淡季
}else{
//表示键盘录入的月份是一个非法数据
System.out.println("键盘录入的月份不合法");
}
System.out.println(ticket +"折");
}
}