9.6总结
package com.itzihan.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();
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;
case "经济舱":
money *= 0.85;//
break;
default:
System.out.println("您输入的仓位信息有误~~");
money = -1;
}
}else if (month == 11 || month == 12 || month >=0 && month <=4 ){
//淡季
switch (type){
case "头等舱":
money *= 0.7;//
break;
case "经济舱":
money *= 0.65;//
break;
default:
System.out.println("您输入的仓位信息有误~~");
money = -1;
}
}else {
System.out.println("对不起,您输入的月份有误~~");
return -1;//表示输入的信息有误
}
return money;
//到此,开始调用方法,返回以上主代码
}
}

浙公网安备 33010602011771号