-->
当前位置:首页 > 题库

函数题:租车服务

Luz4年前 (2022-05-25)题库586
某租车公司提供租车服务,针对不同的车辆类型,日租金的计算方式不同,具体地,对于货车而言,根据载重量load(单位是吨)计算,公式为loadx 1000;对于大型客车而言,根据车内座位数seats计算,公式为seatsx50;对于小型汽车而言,根据车辆等级和折旧年数计算,公式为200*level/sqrt(year),其中sqrt表示平方根。设计合适的类继承结构实现上述功能,构造租车公司类CarRentCompany,提供静态函数rentVehicles,能够给定一组待租车辆,计算日租金总额。 在main函数中,读入多个车辆数据,并计算总的日租金。

### 方法接口定义:
java
public static double rentVehicles(Vehicle[] vehicles); // 计算日租金总额


### 裁判测试程序样例:
java
import java.util.Scanner;

public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
Vehicle[] vs = new Vehicle[n];
for (int i=0;i<n;i++) {
int type = sc.nextInt();
if (type == 1) {//货车
vs[i] = new Truck (sc.nextDouble());
} else if (type == 2) {
vs[i] = new Keche(sc.nextInt());
} else if (type == 3) {
vs[i] = new Car(sc.nextInt(), sc.nextInt());
}
}
System.out.printf("%.2f",CarRentCompany.rentVehicles(vs));
}
}

/* 你的代码被嵌在这里 */


### 输入描述:

汽车数量 汽车种类 该类汽车相关属性 其中1表示货车,2表示大型客车,3表示小型汽车

### 输出描述:

总的日租金,保留两位小数

### 输入样例:

in
3
1 3
2 50
3 5 5


### 输出样例:

out
5947.21






答案:若无答案欢迎评论