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

xiaoxiao2021-02-28  50

Time Limit: 1000 ms Memory Limit: 65536 KiB Submit Statistic 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(含义同上) Sample Input 1 2 1 1 2 2 Sample Output 15 0.00 1600 Hint

Source zhouxq

import java.util.*; class myclass { int ren; double huo; int tian; myclass(int a, double b, int c) { ren = a; huo = b; tian = c; } } class Main { public static void main(String[] args) { Scanner ss = new Scanner(System.in); int flag; int n; myclass my[] = new myclass[15]; int a[] = { 5, 5, 5, 51, 55, 5, 5, 0, 0, 0 }; double b[] = { 0.0, 0.0, 0.0, 0.0, 0.0, 0.45, 2.0, 3.0, 25.0, 35.0 }; int c[] = { 800, 400, 800, 1300, 1500, 500, 450, 200, 1500, 2000 }; for (int i = 0; i < 10; i++) { my[i] = new myclass(a[i], b[i], c[i]); } while (ss.hasNextInt()) { flag = ss.nextInt(); if (flag == 0) { System.out.println("0 0.00 0"); break; } else { n = ss.nextInt(); int suma = 0; double sumb = 0.0; int sumc = 0; while (n > 0) { int num, day; num = ss.nextInt(); day = ss.nextInt(); suma += my[num - 1].ren * day; sumb += my[num - 1].huo * day; sumc += my[num - 1].tian * day; n--; } System.out.printf("%d %.2f %d\n", suma, sumb, sumc); } } ss.close(); } }
转载请注明原文地址: https://www.6miu.com/read-2619785.html

最新回复(0)