答答租车

答答租车系统(面向对象综合练习)

Time Limit: 1000MS Memory Limit: 65536KB

Problem Description

各位面向对象的小伙伴们,在学习了面向对象的核心概念——类的封装、继承、多态之后,答答租车系统开始营运了。

请你充分利用面向对象思想,为公司解决智能租车问题,根据客户选定的车型和租车天数,来计算租车费用,最大载客人数,最大载载重量。

公司现有三种车型(客车、皮卡车、货车),每种车都有名称和租金的属性;其中:客车只能载人,货车只能载货,皮卡车是客货两用车,即可以载人,也可以载货。

下面是答答租车公司的可用车型、容量及价目表:
序号     名称     载客量      载货量        租金
                           (人)     (吨)    (元/天)
  1          A            5                                 800
  2          B            5                                 400
  3          C            5                                 800
  4          D            51                             1300
  5          E            55                             1500
  6          F             5            0.45             500
  7         G             5             2.0               450
  8         H                            3                  200
  9          I                             25              1500
 10        J                             35              2000

要求:根据客户输入的所租车型的序号及天数,计算所能乘载的总人数、货物总数量及租车费用总金额。

Input
首行是一个整数:代表要不要租车 1——要租车(程序继续),0——不租车(程序结束);

第二行是一个整数,代表要租车的数量N;

接下来是N行数据,每行2个整数m和n,其中:m表示要租车的编号,n表示租用该车型的天数。

Output
若成功租车,则输出一行数据,数据间有一个空格,含义为:

载客总人数 载货总重量(保留2位小数) 租车金额(整数)

若不租车,则输出: 

0 0.00 0(含义同上)

Example Input
1
2
1 1
2 2
Example Output
15 0.00 1600

//数组的赋值可以在定义的时候赋值,代码量可减少
import java.util.*;


public class Main {

	public static void main(String[] args) {
       Scanner reader=new Scanner(System.in);
       int n=reader.nextInt();
        if(n==1){
        	int num=reader.nextInt();
        	int a [] = new int [10];
        	int b[] = new int [10];
        	 double c[] = new double [10];
        	 int[] d = new int [10];
        	 for(int i=0;i<10;i++){
     		    a[i]=i+1;
     		    b[i]=0;
     		   c[i]=0;
     		   d[i]=0;
     		}
     		b[1]=b[0]=b[2]=b[5]=b[6]=5;
     		b[3]=51;
     		b[4]=55;
     	
     		c[5]=0.45;
     		c[6]=2.0;c[7]=3;
     		c[8]=25;c[9]=35;
     		d[0]=800;
     		d[1]=400;d[2]=800;d[3]=1300;
     		d[4]=1500;d[5]=500;
     		d[6]=450;d[7]=200;d[8]=1500;d[9]=2000;
           Da z=new Da(a,b,c,d);
           int p[]=new int[10];
           int k[]=new int [10];
           for(int i=0;i<num;i++)
           {
        	   p[i]=reader.nextInt();
        	   k[i]=reader.nextInt();
           }
           
           z.add(num, p, k);
        }
        else {
        	System.out.println("0 0.00 0");
        }

}
}
class Da   {
	public int[] a;
	public int b[];
	public double c[];
	public int d[];
	
	public Da(int[] a2, int[] b2, double[] c2, int[] d2) {
		// TODO Auto-generated constructor stub
		this.a=a2;
		this.b=b2;
		this.c=c2;
		this.d=d2;
	}
	public void add(int n,int p[],int k[]){
		int sum1=0;
		double sum2=0;
		int sum3=0;
		
		int j=0;
		for(j=0;j<n;j++){
		for(int i=0;i<10;i++){
			if(p[j]==a[i]){
				sum1+=b[i]*k[j];
				sum2+=c[i]*k[j];
				sum3+=d[i]*k[j];
				break;
			}
		}
	  }
		System.out.println(sum1+" "+String.format("%.2f", sum2)+" "+sum3);
	}
	
}


### 答达租车 Python 开发或脚本示例 #### 出租车费用计算函数 为了实现答达租车的费用计算功能,可以基于北京市计程出租汽运价管理规定创建一个简单的费用计算器。此函数会考虑基础价格、里程费以及等待时间等因素。 ```python def calculate_taxi_fare(distance_km, wait_minutes=0): base_fare = 13.0 # 基础起步价 distance_rate = 2.3 # 每公里单价 fare = base_fare + max(0, distance_km - 3) * distance_rate # 计算超过起始里程后的费用 if wait_minutes > 0: waiting_charge = round(wait_minutes / 5) * 2.5 # 每等候五分钟加收2.5元 fare += waiting_charge return round(fare, 2) print(calculate_taxi_fare(7.5)) # 输出应支付金额 ``` 该代码片段定义了一个名为 `calculate_taxi_fare` 的函数,用于模拟根据行驶距离可能存在的停等待时间来估算乘客应付给司机的具体数额[^4]。 #### 使用机器学习预测出租车费用 对于更复杂的场景,比如想要提前预估行程成本,则可以通过训练模型来进行预测。这里提供一段简化版的例子,展示如何利用历史数据集构建并评估一个二元分类器以估计纽约市内的打花费范围: ```python import pandas as pd from sklearn.model_selection import train_test_split from sklearn.linear_model import LogisticRegression from sklearn.metrics import accuracy_score # 加载样本数据集(此处仅为示意) data = { 'pickup_latitude': [...], 'pickup_longitude':[...], 'dropoff_latitude':[...], 'dropoff_longitude':[...], 'fare_amount': [...]} df = pd.DataFrame(data) X = df.drop('fare_amount', axis=1).values y = (df['fare_amount'] >= median_fare).astype(int) # 将票价分为高低两类 # 划分测试集合训练集 X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=.2, random_state=42) model = LogisticRegression() model.fit(X_train, y_train) predictions = model.predict(X_test) accuracy = accuracy_score(y_test, predictions) print(f'Accuracy: {accuracy:.2f}') ``` 这段程序展示了怎样运用逻辑回归算法建立一个简易的成本区间判断工具,并对其性能进行了初步检验[^1]。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值