package com.studentSys.ch2;
import java.util.Scanner;
public class ch2Demo3 {
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();
//2.先判断月份是旺季还是淡季
if(month>=5 && month<=10){
}else if(month>=1 && month<=4 || month>=11 && month<=12){
if(seat==0){
//旺季
//3.继续判断当前是头等舱还是经济舱
ticket=getPrice(ticket,seat,0.9,0.85);
}else if(seat==1){
//淡季
getPrice(ticket,seat,0.7,0.65);
}else{
//表示键盘录入的月份是一个非法的数据
System.out.println("没有这个舱位");
}
}else{
System.out.println("键盘录入的月份是不合法的");
}
System.out.println(ticket);
}
public static int getPrice(int ticket,int seat,double v0,double v1){
if(seat==0){
ticket = (int)(ticket * v0);
}else if(seat==1){
ticket = (int)(ticket * v1);
}else{
System.out.println("没有这个舱位");
}
return ticket;
}
}
java学习第三天
于 2024-03-20 14:59:31 首次发布
![](https://img-home.csdnimg.cn/images/20240611030827.png)