package com.imooc;
import java.util.Scanner;
public class CarRent {
static Car[] cars = { new Manned(1, "奥迪A4", 500, 4), new Manned(2, "马自达6", 400, 4),
new PickUp(3, "皮卡雪6", 450, 4, 2), new Manned(4, "金龙", 800, 20), new CargoCar(5, "松花江", 400, 4),
new CargoCar(6, "依维柯", 1000, 20) };
public void show() {
for (Car i : cars) {
System.out.println(i);
}
}
public static void Calulate(int carnum) { //carnum用户输入的租车数量
int[] carn = new int[carnum]; //根据用户输入的租车数量建立对应大小的数组
for (int i = 1; i < carnum + 1; i++) {
System.out.println("请输入第" + i + "辆车的序号:");
Scanner sc3 = new Scanner(System.in);
carn[i - 1] = sc3.nextInt() - 1; //将用户输入的车辆序号存到carn数组中
}
System.out.println("请输入租车天数:");
Scanner sc4 = new Scanner(System.in);
int day = sc4.nextInt();
System.out.println("您的账单:");
System.out.println("***可载人的车有:");
int TotalManned = 0;
int TotalCargo = 0;
int TotalPrice = 0;
for (int i = 0; i < carn.length; i++) { //计算对应载人车量的载人数
if (cars[carn[i]] instanceof Manned || cars[carn[i]] instanceof PickUp) {
TotalManned += cars[carn[i]].getManned();
System.out.print(cars[carn[i]].getName() + "\t");
}
}
System.out.println("共载人:" + TotalManned + "人");
System.out.println("***可载货的车有:");
for (int i = 0; i < carn.length; i++) {
if (cars[carn[i]] instanceof CargoCar || cars[carn[i]] instanceof PickUp) {
TotalCargo += cars[carn[i]].getCargo();
System.out.print(cars[carn[i]].getName() + "\t");
}
}
System.out.println("共载货:" + TotalCargo + "吨");
for (int i = 0; i < carn.length; i++) {
TotalPrice += cars[carn[i]].getPrice();
}
System.out.println("***租车总价格:" + TotalPrice * day + "元");
}
}
点击查看更多内容
1人点赞
评论
共同学习,写下你的评论
评论加载中...
作者其他优质文章
正在加载中
感谢您的支持,我会继续努力的~
扫码打赏,你说多少就多少
赞赏金额会直接到老师账户
支付方式
打开微信扫一扫,即可进行扫码打赏哦