出租车收费

package day1_test;

import java.util.Scanner;
public class list1 {

public static void main(String[] args) {
	 System.out.println("请输入里程数");
		Scanner input =new Scanner(System.in);
		double road =input.nextDouble();
		double costRoad=costRoad(road);
	 System.out.println("里程费为"+costRoad+"元");
	 double costLow=costLow();
	 System.out.println("低速行驶费为"+costLow+"元");
	 double costServe=costServe();
	 System.out.println("服务费为"+costServe+"元");
	 double costEmpty=costEmpty(road); 
	 System.out.println("空驶费为"+costEmpty+"元");
	 System.out.println("请输入开始时间0-24");
		int T1=input.nextInt();
		System.out.println("请输入结束时间0-24");
		int T2=input.nextInt();
		double costNight=costNight(T1,T2,road);
		 System.out.println("额外夜间行驶费为"+costNight+"元");
	 double costAll=costAll(costRoad,costLow,costServe,costServe,costEmpty,costNight);
	 int judge = (int)(costAll*10%10);
	 if(judge>=5) {
		costAll=(int) costAll+1;
	 }
	 else {
		 costAll=(int)costAll;
	 }
	 System.out.println("燃油费"+1+"元");
	 System.out.println("总费用为"+costAll+"元");
	
}

private static double costAll(double costRoad, double costLow, double costServe, double costServe2,
		double costEmpty, double costNight) {
	double sum =costRoad+costLow+costServe+costServe+costEmpty+costNight+1;
	return sum;
}

private static double costNight(int T1,int T2,double road) {
	double night;
	if(5<=T1&&T1<23 && 5<=T2&&T2<23&&T1<T2) {
		System.out.println("为非夜间行驶");
		return 0;
	}
	else
		System.out.println("夜间行驶");
		night=(road-3)*0.2*2.3;	
	return night;
}

private static double costEmpty(double road) {
	if(road>15) {
		double sum =(road-15)*0.5*2.3;
		System.out.println("空车费为"+sum+"元");	
		return sum;
	}
		
	return 0;
}

private static double costServe() {
	double serve;
	System.out.println("1.叫车服务并未超过4小时填 --> 1,  2.叫车服务并超过4小时填 -->2   3. 不叫车服务填--->0");
	Scanner input =new Scanner(System.in);
	String judge= input.next();
	switch(judge) {
	case "0":
		break;
	case"1":
		return serve=5;
		
	case"2":
		return serve=6;
		
		default:
			System.out.println("输入错误");
		
	
		
	}
	return 0;
}

private static double costLow() {
	System.out.println("请输入低速时长");
	Scanner input =new Scanner(System.in);
	
	double time=input.nextDouble(),costLow;
	costLow=(time/5)*2;
	return costLow;
}

private static double costRoad(double road) {
	double costRoad;
	if(road>3) {
		costRoad=13+(road-3)*2.3;
		return costRoad;
	}
	else
	return 13;
}

}

猜你喜欢

转载自blog.csdn.net/chh1ctrl/article/details/113086591