public class Ticket{
private float price = 5000;
public float getPrice(int month, int cabin){
float discount = 0;
if (month >= 4 && month <= 10) {
if (cabin==1) {
discount = 0.9f;
}else{
discount = 0.5f;
}
}else{
if (cabin==1) {
discount = 0.8f;
}else{
discount = 0.4f;
}
}
return price * discount;
}
public static void main(String[] args) {
Ticket test = new Ticket();
System.out.println("4月旺季要去海南旅游:头等仓标价:" + test.getPrice(4, 1));
System.out.println("10月旺季要去海南旅游:经济仓标价:" + test.getPrice(10, 2));
System.out.println("3月淡季要去海南旅游:头等仓标价:" + test.getPrice(3, 1));
System.out.println("11月淡季要去海南旅游:经济仓标价:" + test.getPrice(11, 2));
}
}