python出租车收费标准_java 计程车计费(示例代码)

/**

1.声明好程序所需的变量,用于存储数据,请注意数据类型。

2.提示用户输入总里程数、总乘车时间、是否预约叫车

(如果是预约叫车 还需要确认是否在4小时以内)、

是否有低速行驶(如果有,提示输入低速行驶时间,

需要考虑早晚高峰),

分别将这些用户输入的值,通过赋值存入对应的变 量中。

@since 2020-7-1

@author Administrator

*/

import java.util.Scanner;

public class CostOfTaxi {

//起步价

float startingPrice = 13.0f ;

//行驶里程

float inputMileage = 0.0f;

float mileage = 0.0f;

//基本单价

float basicUnitPrice = 2.3f;

//油费

float oilCost = 1.0f;

//总消费

float sumOfCost = 0.0f;

public static void main (String[] arg) {

// hanlong乘车

CostOfTaxi hanlong = new CostOfTaxi ();

hanlong.CostOfTaxi();

}

void CostOfTaxi () {

System.out.println("*********计程车收费**********");

System.out.println();

System.out.print("请输入行驶里程(千米): ");

Scanner inputif = new Scanner(System.in);

inputMileage = inputif.nextInt();

System.out.print("输入上车时间:hh:mm ");

String upCar = inputif.next();

int upCarHour = Integer.parseInt(upCar.substring(0, 2));

int upCarMinute = Integer.parseInt(upCar.substring(3, 5));

System.out.print("输入下车时间: ");

String downCar = inputif.next();

int downCarHour = Integer.parseInt(downCar.substring(0, 2));

int downCarMinute = Integer.parseInt(downCar.substring(3, 5));

System.out.print("输入是否预约叫车(是|否): ");

String ifAppointment = inputif.next();

System.out.print("预约时间是否在4小时以内(是|否):");

String ifShortAppointmentTime = inputif.next();

System.out.print("是否让司机等候或低速行驶(是|否): ");

String ifLowSpeed = inputif.next();

System.out.print("请输入不含早晚高峰期间低速行驶时长(分钟):");

int withoutPeakTime = inputif.nextInt();

System.out.print("请输入早晚高峰期间低速行驶时长(分钟):");

int peakTime = inputif.nextInt();

System.out.print("是否往返(起点终点2公里)(是|否):");

String ifNoPassengers = inputif.next();

System.out.println();

String ifNightCar = "否";

if (upCarHour>=23 || downCarHour <=5 || upCarMinute>=23 || downCarMinute<=5) {

ifNightCar = "是";

}

inputif.close();

System.out.println();

System.out.println("*****费用明细*****");

float sumOfCost = startingPrice + oilCost;

sumOfCost = sumOfCost

//以下方法会额外收费

//超过三公里

+ over3Km()

//慢速行驶(12公里时以下), +2*basicUnitPrice/5 min;非高峰+basicUnitPrice/5 min

+ lowSpeed(ifLowSpeed,withoutPeakTime,peakTime)

//预约 <= 4: 5, >4:6

+ appointment(ifAppointment,ifShortAppointmentTime)

//空驶 往返(起点终点2公里):0;不往返>15 +0.5*basicUnitPrice

+ noPassengers(ifNoPassengers)

//夜间行驶 题目理解为23-5上车就算钱,而不是23-5内行驶的公里数算钱

+ nightCar(ifNightCar);

System.out.println("油费: 1.0元");

System.out.println("总车费:" + Math.round(sumOfCost) + "元");

}

public float over3Km() {

// TODO Auto-generated method stub

float over3kmCost = 0;

if (inputMileage > 3) {

over3kmCost = basicUnitPrice * (inputMileage - 3);

System.out.println("里程超过3公里,里程价格:" + over3kmCost+ "元");

} else {

System.out.println("3公里内,里程价格:" + over3kmCost+ "元");

}

return over3kmCost;

}

public float nightCar(String ifNightCar) {

// TODO Auto-generated method stub

float nightCarCost;

if (ifNightCar.equals("是")) {

nightCarCost = (float) ((inputMileage - 3)*0.2*basicUnitPrice);

}else {

nightCarCost = 0 ;

}

System.out.println("夜间收费:" + nightCarCost + "元");

return nightCarCost ;

}

public float noPassengers(String ifNoPassengers) {

// TODO Auto-generated method stub

float noPassengersCost = 0.0f;

if ((inputMileage > 15) && ifNoPassengers.equals("否")) {

noPassengersCost = (float) ((inputMileage - 15)*0.5*basicUnitPrice);

} else {

noPassengersCost = 0;

}

System.out.println("空驶费:" + noPassengersCost + "元");

return noPassengersCost;

}

public float lowSpeed(String ifLowSpeed, int withoutPeakTime, int peakTime) {

// TODO Auto-generated method stub

float lowSpeedCost = 0.0f;

if (ifLowSpeed.equals("是")) {

lowSpeedCost = (withoutPeakTime / 5) * 1 * basicUnitPrice+(peakTime / 5) * 2 * basicUnitPrice;;

}

else {

lowSpeedCost = 0.0f;

}

System.out.println("低速行驶或司机等候服务费:" + lowSpeedCost + "元");

return lowSpeedCost;

}

public float appointment(String ifAppointment, String ifShortAppointmentTime) {

float appointmentCost = 0.0f;

if (ifAppointment.equals("是")) {

if (ifShortAppointmentTime.equals("是")) {

appointmentCost = 4;

} else {

appointmentCost = 6;

}

}

System.out.println("预约叫车服务费:" + appointmentCost + "元");

return appointmentCost;

}

}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值