JAVA案例:买飞机票

package com.itheima.anli;

public class Anli1 {
    public static void main(String[] args) {
        calculate(1000,8,"经济舱");
        System.out.println( calculate(1000,8,"经济舱"));
    }
    public static double calculate(double price,int month,String type){
        if(month>=5&&month<=10){
            switch (type){
                case "头等舱":
                    price *=0.9;
                    break;
                case "经济舱":
                    price *=0.85;
                    break;
            }
        }
        else {
            switch (type){
                case "头等舱":
                    price *=0.7;
                    break;
                case "经济舱":
                    price *=0.65;
                    break;
            }
        }
        return price;
    }
}

 

 

posted @ 2024-02-29 22:07  小彭先森  阅读(12)  评论(0编辑  收藏  举报