答答租车系统(面向对象综合练习)
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
第二行是一个整数,代表要租车的数量N;
接下来是N行数据,每行2个整数m和n,其中:m表示要租车的编号,n表示租用该车型的天数。
Output
载客总人数 载货总重量(保留2位小数) 租车金额(整数)
若不租车,则输出:
0 0.00 0(含义同上)
Sample Input
1 2 1 1 2 2
import java.math.BigInteger;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Scanner;
import java.util.Set;
import java.util.TreeSet;
public class Main {
public static void main(String[] args) throws ParseException {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int count = 0;
double sum = 0.0;
int price = 0;
if(n == 0)
{
System.out.println("0 0.00 0");
}
else
{
int t = sc.nextInt();
car a[] = {new keche(1,5,800),new keche(2,5,400),
new keche(3,5,800), new keche(4,51,1300),
new keche(5,55,1500), new pika(6,5,0.45,500),
new pika(7,5, 2.0,450), new huoche(8,3,200),
new huoche(9,25,1500),new huoche(10,35,2000)};
for(int i = 0; i < t; i++)
{
int m = sc.nextInt();
int b = sc.nextInt();
count += a[m-1].count*b;
sum +=a[m-1].sum*b;
price += a[m-1].price*b;
//System.out.printf("%d %.2f %d\n",a[m-1].count, a[m-1].sum, a[m-1].price);
}
System.out.printf("%d %.2f %d\n", count, sum, price);
}
}
}
class car{
public int id ,count;
public double sum;
public int price;
}
class keche extends car{
public keche(int id, int count, int price) {
this.id = id;
this.count = count;
this.price = price;
}
}
class huoche extends car{
public huoche(int id, double sum, int price) {
this.id = id;
this.sum = sum;
this.price = price;
}
}
class pika extends car{
public pika(int id, int count, double sum, int price) {
this.id = id;
this.count = count;
this.sum = sum;
this.price = price;
}
}
这是一篇面向对象编程的实践练习,要求设计一个答答租车系统,根据客户选择的车型和租赁天数,计算租车费用、最大载客人数和最大载货重量。系统涵盖多种车型,如客车、皮卡车和货车,每种车有不同的载客量、载货量和租金。用户输入车型序号和租赁天数,系统返回总人数、总重量和总费用。
1598

被折叠的 条评论
为什么被折叠?



