package qwr;
import java.util.Scanner;
/**
* Created by Administrator on 2016/12/2.
*/
public class Initial {
static int is = 0;
public static void main(String[] args) {
Initial it = new Initial();
System.out.println("请问您是否需要租车?");
System.out.println("输入:1进入挑选 输入0:退出");
do {
Scanner sc = new Scanner(System.in);
int isof = sc.nextInt();
if (isof == 0) {
System.out.println("欢迎您下次光临!");
break;
} else if (isof == 1) {
System.out.println("请挑选你想选择的车辆!");
is = isof;
it.test();
break;
} else {
System.out.println("输入有误,请重新输入!");
continue;
}
}while (true);
}
public void test() {
Didi[] carsForRent = {
new PassengerCar("奥迪A4", 500, 4),
new PassengerCar("马自达6", 500, 4),
new PickUp("皮卡雪6", 450, 4, 2),
new PassengerCar("金龙", 800, 20),
new CurrentCar("松花江", 400, 4),
new CurrentCar("依维柯", 1000, 20)};
int i = 1;
if (is == 1) {
for (Didi currentCar : carsForRent) {
if (currentCar instanceof PassengerCar) {
System.out.println("" + i + "\t" + currentCar.getName() + "\t" + currentCar.getRentm() + "元/天" + "\t" + "载人:" + currentCar.getTake() + "人");
i++;
} else if (currentCar instanceof PickUp) {
System.out.println("" + i + "\t" + currentCar.getName() + "\t" + currentCar.getRentm() + "元/天" + "\t" + "载人:" + currentCar.getTake() + "人" + "载货:" + currentCar.getTon() + "吨");
i++;
} else {
System.out.println("" + i + "\t" + currentCar.getName() + "\t" + currentCar.getRentm() + "元/天" + "\t" + "载货:" + currentCar.getTon() + "吨");
i++;
}
}
}
double money = 0;
do {
System.out.println("请输入你想要租车的序号(选购完成请输入0):");
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
if (n == 0) {
System.out.println("欢迎您下次光临!");
System.out.println("**租车总价格:" + money + "元");
System.out.println("**可载人的车有:");
int sumper = 0;
for (int x = 0; x < 6; x++) {
if (carsForRent[x].getRentsum() > 0 && carsForRent[x].getTake() > 0) {
System.out.print(carsForRent[x].getName() + "x" + carsForRent[x].getRentsum());
sumper = sumper + carsForRent[x].getRentsum() * carsForRent[x].getTake();
}}
if (sumper > 0) {
System.out.println("\t" + "可载人: " + sumper + "人");
}
else{
System.out.println("无车可载人!");
}
int ton = 0;
System.out.println("**可载货的车有:");
for (int x = 0; x < 6; x++) {
if (carsForRent[x].getRentsum() > 0 && carsForRent[x].getTon() > 0) {
System.out.print(carsForRent[x].getName() + "x" + carsForRent[x].getRentsum());
ton = ton + carsForRent[x].getRentsum() * carsForRent[x].getTon();
}
}
if (ton > 0) {
System.out.println("\t" + "可载货:" + ton + "吨");
} else {
System.out.println("无车可载货!");
}
break;}
else if (n == 1 || n == 2 || n == 3 || n == 4 || n == 5 || n == 6) {
switch (n) {
case 1:
System.out.println("请输入你想要租车的数量:");
int sum = sc.nextInt();
carsForRent[n - 1].setRentsum(sum);
double m1 = 500 * sum;
System.out.println("请输入你想要租用的天数:");
money = money + m1 * sc.nextInt();
break;
case 2:
System.out.println("请输入你想要租车的数量:");
sum = sc.nextInt();
carsForRent[n - 1].setRentsum(sum);
m1 = 400 * sum;
System.out.println("请输入你想要租用的天数:");
money = money + m1 * sc.nextInt();
break;
case 3:
System.out.println("请输入你想要租车的数量:");
sum = sc.nextInt();
carsForRent[n - 1].setRentsum(sum);
m1 = 450 * sum;
System.out.println("请输入你想要租用的天数:");
money = money + m1 * sc.nextInt();
break;
case 4:
System.out.println("请输入你想要租车的数量:");
sum = sc.nextInt();
carsForRent[n - 1].setRentsum(sum);
m1 = 800 * sum;
System.out.println("请输入你想要租用的天数:");
money = money + m1 * sc.nextInt();
break;
case 5:
System.out.println("请输入你想要租车的数量:");
sum = sc.nextInt();
carsForRent[n - 1].setRentsum(sum);
m1 = 400 * sum;
System.out.println("请输入你想要租用的天数:");
money = money + m1 * sc.nextInt();
break;
case 6:
System.out.println("请输入你想要租车的数量:");
sum = sc.nextInt();
carsForRent[n - 1].setRentsum(sum);
m1 = 1000 * sum;
System.out.println("请输入你想要租用的天数:");
money = money + m1 * sc.nextInt();
break;}
}
else{
System.out.println("输入有误,请重新输入!");
continue;}
}while (true) ;
}
}