今天给大家分享一个Java小项目--计算飞机票价。
题目要求:票价计算分为商务舱和经济舱,月份分两个阶段,一个为5-10月;一个为1-4,11-12月,商务舱在5-10月折扣为9折,经济舱为85折;商务舱在另外一个月份折扣为7折,经济舱为65折,请根据不同的情况,计算出票价。
import java.util.Scanner;
public class Demo33 {
public static void main(String[] args) {
//键盘录入
Scanner sc = new Scanner(System.in);
System.out.println("请输入机票原价");
int price = sc.nextInt();
System.out.println("请输入当前月份");
int month = sc.nextInt();
System.out.println("请输入你的舱位 0 为经济舱 1 为商务舱");
int seat = sc.nextInt();
首先,进行键盘录入,将题目所需的要求通过这个方式输入进去。
//通过多种if-elif语句体来进行判断和价格计算
if(month >= 5 && month<= 10){
if (seat == 0){
price = (int)(price * 0.9);
}else if(seat == 1){