package com.exc;import java.util.Scanner;public class DDRental { public static void main(String[] args) { int money =0; Car[] carForRentCars = {new AutoCar("奥迪", 500, 4), new AutoCar("马自达", 400, 4), new AutoCar("金龙", 800, 20) ,new Trunk("松花江", 400, 4), new Trunk("依维柯", 1000, 20), new PickCar("皮卡", 450, 2, 4)}; System.out.println("欢迎使用哒哒租车系统~~~"); System.out.println("您是否要租车:1是 2否"); Scanner sc = new Scanner(System.in); boolean flag = true; while (flag) { int rent = sc.nextInt(); switch (rent) { case 1: System.out.println("您可租车的类型及其价格表如下:"); System.out.println("序号\t汽车名称\t租金\t\t容量"); for (int i = 0; i < carForRentCars.length; i++) { if (carForRentCars[i] instanceof AutoCar) { AutoCar aCar = (AutoCar) carForRentCars[i]; System.out.println((i+1) + "\t" + aCar.name +"\t" + aCar.rent + "元/天\t\t载人:" + aCar.getPeopleCapacity() +"人"); } else if (carForRentCars[i] instanceof Trunk) { Trunk trunk = (Trunk) carForRentCars[i]; System.out.println((i+1) + "\t" + trunk.name +"\t" + trunk.rent + "元/天\t\t载人:" + trunk.getCargoCapacity() +"人"); } else if (carForRentCars[i] instanceof PickCar) { PickCar pCar = (PickCar) carForRentCars[i]; System.out.println((i+1) + "\t" + pCar.name +"\t" + pCar.rent + "元/天\t\t载人:" + pCar.getPeopleCapacity() + "人 载货:"+ pCar.getCargoCapacity() +"吨"); } } flag = false; break; case 2: System.out.println("感谢您的光临,期待下次与您再见,祝您生活愉快!"); flag = false; break; default: System.out.println("您好,您的输入不正确。请根据提示正确输入!"); break; } } System.out.println("请输入您要租车的数量:"); int count = sc.nextInt(); for (int i = 1; i <= count; i++) { System.out.println("请输入第" + i +"辆车的序号:"); int id = sc.nextInt(); switch (id) { case 1: money += carForRentCars[0].getRent(); break; case 2: money += carForRentCars[1].getRent(); break; case 3: money += carForRentCars[2].getRent(); break; case 4: money += carForRentCars[3].getRent(); break; case 5: money += carForRentCars[4].getRent(); break; case 6: money += carForRentCars[5].getRent(); break; default: break; } } System.out.println("请输入租车天数:"); int day = sc.nextInt(); System.out.println("您的帐单:" + day*money + "元!!!"); }}class Car{ String name; int rent; public Car() {} public String getName() { return name; } public void setName(String name) { this.name = name; } public double getRent() { return rent; } public void setRent(int rent) { this.rent = rent; } }class AutoCar extends Car{ private int peopleCapacity; public AutoCar() {} public AutoCar(String name, int rent, int peopleCapacity) { this.name = name; this.rent = rent; this.peopleCapacity = peopleCapacity; } public int getPeopleCapacity() { return peopleCapacity; } public void setPeopleCapacity(int peopleCapacity) { this.peopleCapacity = peopleCapacity; } }class Trunk extends Car{ private int cargoCapacity; public Trunk() {} public Trunk(String name, int rent, int cargoCapacity) { this.name = name; this.rent = rent; this.cargoCapacity = cargoCapacity; } public int getCargoCapacity() { return cargoCapacity; } public void setCargoCapacity(int cargoCapacity) { this.cargoCapacity = cargoCapacity; } }class PickCar extends Car{ private int cargoCapacity; private int peopleCapacity; public PickCar() {} public PickCar(String name, int rent, int cargoCapacity, int peopleCapacity) { this.name = name; this.rent = rent; this.cargoCapacity = cargoCapacity; this.peopleCapacity = peopleCapacity; } public int getCargoCapacity() { return cargoCapacity; } public void setCargoCapacity(int cargoCapacity) { this.cargoCapacity = cargoCapacity; } public int getPeopleCapacity() { return peopleCapacity; } public void setPeopleCapacity(int peopleCapacity) { this.peopleCapacity = peopleCapacity; } }