java 计程车计费
2021-05-01 07:27
标签:round oat 赋值 arc nis auto 时间 高峰 amp /** public class CostOfTaxi { } java 计程车计费 标签:round oat 赋值 arc nis auto 时间 高峰 amp 原文地址:https://www.cnblogs.com/javahanlong/p/13220913.html
需要考虑早晚高峰),
分别将这些用户输入的值,通过赋值存入对应的变 量中。
*/
import java.util.Scanner;
//起步价
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 =23 || downCarMinute4: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;
}
上一篇:spring tx——@EnableTransactionManagement
下一篇:【python】json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)!!!