package Demo;
import java.util.Scanner;
public class Test1 {
public static void main(String[] args) {
//目标:完成飞机票的价格计算
//1、让用户输入机票原价、月份、仓位类型
Scanner sc = new Scanner(System.in);
System.out.println("请您输入机票原价: ");
double money = sc.nextDouble();
System.out.println("请您输入机票的月份(1-12): ");
int month = sc.nextInt();
System.out.println("请您选择仓位类型: ");
String type = sc.next();
//4.调用方法输出最终价格
System.out.println("机票优惠后的价格是:" + calc(money, month, type) + "元");
}
//2.定义方法接收信息,计算优惠后价格
public static double calc(double money, int month, String type){
if (month > 5 && month <= 10) {
//旺季
switch (type) {
case "头等舱":
money *= 0.9;
break;
【Java练习】计算机票优惠价格
最新推荐文章于 2023-04-17 18:58:15 发布