采用方法解决 买飞机票问题
package kkk;
import java.util.Scanner;
public class test1 {
public static void main(String[]args) {
Scanner sc=new Scanner(System.in);
int month=sc.nextInt();
int ticket=sc.nextInt();
int seat=sc.nextInt();
if(month>=5&&month<=10) {
ticket=getprice(ticket,seat,0.9,0.85);
}else if((month>=1&&month<=4)||(month>=11&&month<=12)) {
ticket=getprice(ticket,seat,0.7,0.65);
}else {
System.out.println("你输入的月份有误");
}
System.out.println(ticket);
}
public static int getprice(int ticket,int seat,double vo,double v1) {
if(seat==0) {
ticket=(int)(ticket*vo);
}else if(seat==1) {
ticket=(int)(ticket*v1);
}else {
System.out.println("你输入你的舱位有误");
}
return ticket;
}
}
166





