import java.util.ArrayList;
import java.util.Scanner;
class SCar {
int number;
String name;
int money;
SCar(int number, String name, int money) {
this.number = number;
this.name = name;
this.money = money;
}
public int getNumber() {
return number;
}
public String getName() {
return name;
}
public int getMoney() {
return money;
}
}
class Car extends SCar {
int person;
Car(int number, String name, int money, int person) {
super(number, name, money);
this.person = person;
}
public int getPerson() {
return person;
}
public String toString() {
return "车辆编号:" + number + "\t 车型:" + name + "\t 每天租金:" + money + "\t 可载人数:" + person ;
}
}
class Pick extends Car {
int goods;
Pick(int number, String name, int money, int person, int goods) {
super(number, name, money, person);
this.goods = goods;
}
public int getGoods() {
return goods;
}
public String toString() {
return "车辆编号:" + number + "\t 车型:" + name + "\t 每天租金" + money + "\t 可载人数:" + person + "\t 可载货物吨数:" + goods;
}
}
class Turck extends SCar {
int goods;
Turck(int number, String name, int money, int goods) {
super(number, name, money);
this.goods = goods;
}
public int getGoods() {
return goods;
}
public String toString() {
return "车辆编号:" + number + "\t 车型:" + name + "\t 每天租金:" + money + "\t 可载货物吨数:" + goods;
}
}
public class LianXi {
public static void main(String[] args) {
System.out.println("欢迎来到Dehy租车系统");
System.out.println("是否进入租车系统:1-是 0-否");
Scanner scanner = new Scanner(System.in);
int sc = scanner.nextInt();
if (sc == 0) {
scanner.close();
return;
}
if (sc == 1) {
System.out.println("可租用车辆信息");
Car c1 = new Car(1, "奥迪", 800, 4);
Turck t1 = new Turck(2, "长安", 1000, 10);
Pick p1 = new Pick(3, "福特猛禽", 800, 4, 1);
System.out.println("车辆编号:" + c1.number + "\t车型:" + c1.name + "\t每天租金:" + c1.money + "\t\t可载人数:" + c1.person);
System.out.println("车辆编号:" + t1.number + "\t车型:" + t1.name + "\t每天租金:" + t1.money + "\t\t可载货物吨数:" + t1.goods);
System.out.println("车辆编号:" + p1.number + "\t车型:" + p1.name + "\t每天租金:" + p1.money + "\t\t可载人数:" + p1.person + "\t 可载货物吨数:" + p1.goods);
System.out.println("请输入您需要租车数量");
Scanner scanner1 = new Scanner(System.in);
int sc1 = scanner1.nextInt();
ArrayList<Car> list = new ArrayList();
ArrayList<Turck> list1 = new ArrayList();
ArrayList<Pick> list2 = new ArrayList();
ArrayList list3 = new ArrayList();
int money1 = 0;
for (int i1 = 0; i1 < sc1; i1++) {
System.out.println("请输入车辆编号");
Scanner scanner2 = new Scanner(System.in);
int sc2 = scanner2.nextInt();
System.out.println("租用车辆信息");
if (sc2 == 1) {
System.out.println("车辆编号:" + c1.number + "\t车型:" + c1.name + "\t租金:" + c1.money + "\t\t可载人数:" + c1.person);
list.add(c1);
list3.addAll(list);
money1 = money1 + c1.money;
} else if (sc2 == 2) {
System.out.println("车辆编号:" + t1.number + "\t车型:" + t1.name + "\t租金:" + t1.money + "\t\t可载人数:" + t1.goods);
list1.add(t1);
list3.addAll(list1);
money1 = money1 + t1.money;
} else if (sc2 == 3) {
System.out.println("车辆编号:" + p1.number + "\t车型:" + p1.name + "\t租金:" + p1.money + "\t\t可载人数:" + p1.person + "\t 可载货物吨数:" + p1.goods);
list2.add(p1);
list3.addAll(list2);
money1 = money1 + p1.money;
} else {
System.out.println("输入有误,请重新输入车辆编号! 如想退出程序请输入:0");
System.out.println("请输入车辆编号");
Scanner scanner3 = new Scanner(System.in);
int sc3 = scanner3.nextInt();
System.out.println("租用车辆信息");
if (sc3 == 1) {
System.out.println("车辆编号:" + c1.number + "\t车型:" + c1.name + "\t租金:" + c1.money + "\t\t可载人数:" + c1.person);
list.add(c1);
list3.addAll(list);
money1 = money1 + c1.money;
} else if (sc3 == 2) {
System.out.println("车辆编号:" + t1.number + "\t车型:" + t1.name + "\t租金:" + t1.money + "\t\t可载人数:" + t1.goods);
list1.add(t1);
list3.addAll(list1);
money1 = money1 + t1.money;
} else if (sc3 == 3) {
System.out.println("车辆编号:" + p1.number + "\t车型:" + p1.name + "\t租金:" + p1.money + "\t\t可载人数:" + p1.person + "\t 可载货物吨数:" + p1.goods);
list2.add(p1);
list3.addAll(list2);
money1 = money1 + p1.money;
} else {
scanner3.close();
return;
}
}
}
System.out.println("请输入租车天数");
Scanner scanner3 = new Scanner(System.in);
int sc3 = scanner3.nextInt();
scanner3.close();
int money4 = money1 * sc3;
System.out.println("租赁信息如下:");
StringBuilder sb = new StringBuilder();
for (int i = 0; i < list3.size(); i++) {
sb.append(list3.get(i)+"\r\n");
}
String str = sb.toString();
System.out.println(str);
System.out.println("租用车辆天数:" + sc3);
System.out.println("租车所需金额:" + money4);
}
}
}