public class Car {
int id;
String carName;
int money;
int rongliang;
public static void main(String[] args) {
Car arr[] = new Car[6];
arr[0] = new Car(1, "奥迪A4", 500, 4);
arr[1] = new Car(2, "马自达6", 400, 4);
arr[2] = new Car(3, "奔驰c1", 600, 4);
arr[3] = new Car(4, "宝马", 600, 4);
arr[4] = new Car(5, "大货车", 1200, 50);
arr[5] = new Car(6, "大卡车", 1000, 20);
boolean f = true;
while (f) {
Scanner sc = new Scanner(System.in);
System.out.println("欢迎来到租车系统");
System.out.println("你是否要租车:1.是,2.否");
int a = sc.nextInt();
if (a == 1) {
System.out.println("你可以租车的类型机器价格表如下:");
System.out.println("------------------------------------");
System.out.println("序号" + "t" + "车型" + "t" + "租金" + "t" + "最大载货量或载客量");
System.out.println("------------------------------------");
for (int i = 0; i < arr.length; i++) {
System.out
.println(arr[i].id + "t" + arr[i].carName + "t" + arr[i].money + "t" + arr[i].rongliang);
}
System.out.println("请输入租车的数量");
int b = sc.nextInt();// b是租车的数量
System.out.print("请输入你要租车的序号和天数,中间用空格隔开");
System.out.println();
int c;
int d = 0;
String y = null ;
int m = 0;
int sum = 0;
for (int i = 1; i <= b; i++) {// 判断
c = sc.nextInt();// c输入车的序号
d = sc.nextInt();// d输入天数
y = arr[i - 1].carName;
System.out.println("-----------------------------");
System.out.println(y + "t" + d + "天");
m = arr[i - 1].money+m; // 所租车所需要的钱数
}
System.out.println("-----------------------------");
System.out.println("租车成功!!");
sum += m * d;
System.out.println("-----------------------------");
System.out.println("租车所需的银子"+sum);
System.out.println("-----------------------------");
System.out.println("你的租车账单为:");
System.out.println(y+"t"+d+"天");
System.out.println("租车所需的银子"+sum);
} else if (a == 2) {
f = false;
System.out.println("欢迎下次光临");
break;
}
}
}
public Car(int id, String carName, int money, int rongliang) {
super();
this.id = id;
this.carName = carName;
this.money = money;
this.rongliang = rongliang;
}
}