/* * 案例 * 卖机票 * 需求:机票价格按照淡季和旺季,头等舱和经济舱收费,输入机票原价,月份和头等舱或经济舱 * 旺季(5-10月):头等舱9折,经济舱8.5折 * 淡季(11-来年4月):头等舱7折。经济舱6.5折 * * * 补充:ctr + alt + M 自动抽取方法 * * */
public class Sellingairtickets {
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):");
//使用0,1分别表示头等舱和经济舱
int seat = sc.nextInt();
//2.先判断月份是旺季还是淡季
if(month>=5&&month<=10){
//旺季
ticket = getTicket(ticket, seat, 0.9, 8.5);
// ticket = getprice(ticket,seat,0.9,0.85);
}else if((month>=1&&month<=4)||(month>=11&&month<=12)){
//淡季
ticket = getTicket(ticket, seat, 0.7, 6.5);
// ticket = getprice(ticket,seat,0.7,0.65);
}else{
System.out.println("键盘输入的月份不合法");
}
System.out.println(ticket);
//3.继续判断机票是经济舱还是头等舱
//4.根据情况计算价格
}
private static int getTicket(int ticket, int seat, double v, double v2) {
if (seat == 0) {
//头等舱
ticket = (int) (ticket * v);
} else if (seat == 1) {
//经济舱
//强制类型的转换
ticket = (int) (ticket * v2);
} else {
System.out.println("没有这个舱位");
}
return ticket;
}
}