师傅,你休想,从我这里偷吃油水!

某市出租车计费标准如下图所示,
请根据此标准完成一个出租车计费模拟功能,能够计算总费用和列出产生费用
项目详细情况说明,帮助出租车师傅和乘客了解计费标准

在这里插入图片描述
题目描述:

结合上述表格,可以得出:总车费=里程费用+低速行驶费(或者等候费)
+预约叫车服务费+空驶费+夜间收费+燃油附加费。需要收集的数据有:里程数、 低速行驶时长(早晚高峰期行驶时长和其他时间段行驶时长)、是否预约叫车 (按四小时为标准)、开始乘坐出租车时间、出租车到达终点站时间,结合这
些数据和表中提供的标准就可以使用程序进行计算总车费了

代码:



import java.util.Scanner;
// 抛出异常 测试
public class Taxi {
public static void main(String[] args) {
	Scanner input =new Scanner(System.in);
	//1. 声明好程序所需的变量,用于存储数据,请注意数据类型。
	int  totalCost = 0;
	//里程费用
	double mileageCost = 0;
	//低速行驶费(或者等候费)
	double lowCost =0;
	//预约叫车服务费
	int callCarCosrt =0;
	//空驶费
	double emptyCost =0;
	//夜间收费
	double nightCost =0;
	//燃油附加费
	int oilCost = 0;
	
	//提示用户输入总里程数(符合交付 仍需抛出异常)
	System.out.println("请输入总里程数:");
	double km =0;
	if(input.hasNextDouble())
	{
		km = input.nextDouble();
	}
	else
	{
		System.out.println("你的输入有误!!");
		return;
	}
	//总乘车时间 = 下车时间 - 上车时间
    int onHour = 0;
    int onMinutes = 0;
    int onSeconds = 0;
    
    System.out.println("输入上车时间:");
    System.out.println("时:");
    if (input.hasNextInt()) {
        onHour = input.nextInt();
        if (onHour < 0 | onHour > 23) {
            System.out.println("你的输入有误!!");
            return;
        }
    } else {
        System.out.println("你的输入有误!!");
        return;
    }

    System.out.println("分:");
    if (input.hasNextInt()) {
        onMinutes = input.nextInt();
        if (onMinutes < 0 | onMinutes > 59) {
            System.out.println("你的输入有误!");
            return;
        }
    } else {
        System.out.println("你的输入有误!");
        return;
    }

    System.out.println("秒:");
    if (input.hasNextInt()) {
        onSeconds = input.nextInt();
        if (onSeconds < 0 | onSeconds > 59) {
            System.out.println("你的输入有误!");
            return;
        }
    } else {
        System.out.println("你的输入有误!");
        return;
    }
    
    
    int offHour = 0;
    int offMinutes = 0;
    int offSeconds = 0;
    
    System.out.println("输入下车时间:");
    System.out.println("时:");
    if (input.hasNextInt()) {
        offHour = input.nextInt();
        if (offHour < 0 | offHour > 23) {
            System.out.println("你的输入有误!!");
            return;
        }
    } else {
        System.out.println("你的输入有误!!");
        return;
    }

    System.out.println("分:");
    if (input.hasNextInt()) {
    	offMinutes = input.nextInt();
        if (offMinutes < 0 | offMinutes > 59) {
            System.out.println("你的输入有误!");
            return;
        }
    } else {
        System.out.println("你的输入有误!");
        return;
    }

    System.out.println("秒:");
    if (input.hasNextInt()) {
        offSeconds = input.nextInt();
        if (offSeconds < 0 | offSeconds > 59) {
            System.out.println("你的输入有误!");
            return;
        }
    } else {
        System.out.println("你的输入有误!");
        return;
    }
    //是否预约叫车  

    Boolean appointment = null;
    //是否四小时
    Boolean exceed = null;
    System.out.println("是否预约叫车:(true/false)");
    if (input.hasNextBoolean()) {
        appointment = input.nextBoolean();
        if (appointment) {
            //是不是提前四小时预约
            System.out.println("是不是提前四小时:");
            if (input.hasNextBoolean()) {
                exceed = input.nextBoolean();
            } else {
                System.out.println("输入错误");
                return;
            }
        } else {
            System.out.println("输入有误");
            return;
        }
    }
    
    //是否低速行驶
    Boolean lowSpeed = null;
    //高峰
    int peakDuration = 0;
    //非高峰
    int offpeakDuration = 0;

    System.out.println("是否低速行驶:(true  false   )");
    if (input.hasNextBoolean()) {
        lowSpeed = input.nextBoolean();
        if (lowSpeed) {
            System.out.println("早晚高峰形式的时长低速:分钟");
            if (input.hasNextInt()) {
                peakDuration = input.nextInt();
            }
            System.out.println("早晚非高峰形式的时长低速:分钟");
            if (input.hasNextInt()) {
                offpeakDuration = input.nextInt();
            }

        } else {
            System.out.println("输入有误");
            return;
        }
    }
    //预约费
    if (appointment) {
        if (exceed) {
        	callCarCosrt = 6;
        } else {
        	callCarCosrt = 5;
        }
    }
    //往返载客
    Boolean linger = null;
    if (km >= 15) {
        System.out.println("是否往返载客");
        if (input.hasNextBoolean()) {
            linger = input.nextBoolean();
        } else {
            System.out.println("输入有误");
            return;
        }
    }
  //总车费=里程费用+低速行驶费(或者等候费)+预约叫车服务费+空驶费+夜间收费+燃油附加费。
/*    int  totalCost = 0;
	//里程费用
	double mileageCost = 0;
	//低速行驶费(或者等候费)
	double lowCost =0;
	//预约叫车服务费
	int callCarCosrt =0;
	//空驶费
	double emptyCost =0;
	//夜间收费
	double nightCost =0;
	//燃油附加费
	int oilCost = 0;*/
    //里程费用
    if (km < 3) {
    	mileageCost = 13;
    } else if (km >= 15) {
    	mileageCost = km * 2.3;
        if (linger) {

        } else {
        	emptyCost = mileageCost * 1.5;
        }
    } else {
    	mileageCost = km * 2.3;
    }
    //低速行驶
    if (lowSpeed) {
    	lowCost=(peakDuration/5)*2*2.3+(offpeakDuration/5)*1*2.3;
    }
    //夜间费
    if (onHour==23 | onHour <5 |offHour ==23 | offHour <5){
    	nightCost=1.2*mileageCost;
    }
    
    totalCost =(int)(mileageCost+lowCost+callCarCosrt+emptyCost+nightCost+oilCost);
    System.out.println("总费用:");
    System.out.println(totalCost );
    
    
}
	
}


如果觉得有用就留个赞吧!客官.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

我想去拉萨。

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值