//main方法
package com.yesijie;
import java.util.Scanner;
public class Mainprogram {
public static void main(String[] args) {
// TODO Auto-generated method stub
Welcome welcome=new Welcome();
welcome.welPrint();
welcome.choose();
Salooncar jianianhua=new Salooncar();
jianianhua.setPassengerNum(5);
jianianhua.setName("嘉年华");
jianianhua.setInventory(12);
jianianhua.setPrice(120);
jianianhua.setCargoWeight(0);
Salooncar leikesasi=new Salooncar();
leikesasi.setPassengerNum(4);
leikesasi.setName("雷克萨斯");
leikesasi.setInventory(5);
leikesasi.setPrice(270);
leikesasi.setCargoWeight(0);
Truck jinbei=new Truck();
jinbei.setCargoWeight(10);
jinbei.setName("金杯");
jinbei.setInventory(12);
jinbei.setPrice(90);
jinbei.setPassengerNum(0);
Truck lishi=new Truck();
lishi.setCargoWeight(15);
lishi.setName("力狮");
lishi.setInventory(3);
lishi.setPrice(110);
lishi.setPassengerNum(0);
Picard daoqi=new Picard();
daoqi.setPassengerNum(4);
daoqi.setCargoWeight(5);
daoqi.setName("道奇");
daoqi.setInventory(4);
daoqi.setPrice(240);
Cars cars=new Cars();
Cars []carType={jianianhua,leikesasi,jinbei,lishi,daoqi};
System.out.println("序号 车型 载客量/载货量 库存 租金");
for(int i=0;i<carType.length;i++){//output the information
if(carType[i].getCargoWeight()==0){
System.out.println((i+1)+" "+carType[i].getName()+" "+
carType[i].getPassengerNum()+"人 "+
carType[i].getInventory()+" "+
carType[i].getPrice());
}//end if
else if(carType[i].getPassengerNum()==0){
System.out.println((i+1)+" "+carType[i].getName()+" "+
carType[i].getCargoWeight()+"吨 "+
carType[i].getInventory()+" "+
carType[i].getPrice());
}//end else if
else {
System.out.println((i+1)+" "+carType[i].getName()+" "+
carType[i].getPassengerNum()+"人"+carType[i].getCargoWeight()
+"吨 "+
carType[i].getInventory()+" "+
carType[i].getPrice());
}//end else
}//end for
int carsNumber1;
int totalPeople=0;
int totalWeight=0;
int totalMoney=0;
Scanner input=new Scanner(System.in);
System.out.print("请输入您需要的车辆数量:");
int carNumber=input.nextInt(); //number of cars customer needs
for(int i=0;i<carNumber;i++){//输出租车各项信息
System.out.println("请输入第"+(i+1)+"俩车的序号:");
carsNumber1=input.nextInt();
System.out.println("请输入需要租借的天数:");
int days=input.nextInt();
totalPeople+=carType[carsNumber1-1].getPassengerNum();
totalWeight+=carType[carsNumber1-1].getCargoWeight();
totalMoney+=carType[carsNumber1-1].getPrice()*days;
}//end for
System.out.println();
System.out.println("您的租车信息为:");
for(int i=0;i<carNumber;i++){
System.out.print(carType[carNumber1[i]].getName()+carDays[i]+"天 ");
}//end for
System.out.println();
System.out.println("您的总载人数为"+totalPeople+"人");
System.out.println("您的总载货量为"+totalWeight+"吨");
System.out.println("您的总租金为"+totalMoney+"元");
System.out.println("Thanks for choosing us!");
}//end main()
}
//car类
package com.yesijie;
public class Cars {
private int passengerNum;
private int cargoWeight;
private int price;
private int inventory;
private String name;
public void setPassengerNum(int passengerNum){
this.passengerNum=passengerNum;
}
public int getPassengerNum(){
return passengerNum;
}
public void setCargoWeight(int cargoWeight){
this.cargoWeight=cargoWeight;
}
public int getCargoWeight(){
return cargoWeight;
}
public void setPrice(int price){
this.price=price;
}
public int getPrice(){
return price;
}
public void setInventory(int inventory){
this.inventory=inventory;
}
public int getInventory(){
return inventory;
}
public void setName(String name){
this.name=name;
}
public String getName(){
return name;
}
}
//皮卡子类
package com.yesijie;
public class Picard extends Cars {
}
//轿车子类
package com.yesijie;
public class Salooncar extends Cars {
}
//货车子类
package com.yesijie;
public class Truck extends Cars {
}
//欢迎界面
package com.yesijie;
import java.util.Scanner;
public class Welcome {
public void welPrint(){
System.out.println("欢迎使用达达租车系统!");
System.out.println("请输入数字选择:1.进入系统 2.离开系统");
}
public void choose(){
Scanner input=new Scanner(System.in);
int i=input.nextInt();//输入的数字
if(i==1){
System.out.print("请输入姓名:");
String name=input.next();
System.out.print("请输入您的性别:1.男士 2.女士");
int sex=input.nextInt();
if(sex==1){
System.out.println("欢迎"+name+"先生"+"使用达达租车系统");
}
else if(sex==2){
System.out.println("欢迎"+name+"女士"+"使用达达租车系统");
}
else {
System.out.println("请输入正确的性别!");
welPrint();
choose();
}// end else
}// end if
else if(i==2){
System.out.println("再见!");
}
else{
System.out.println("请输入正确的数字:");
welPrint();
choose();
}//end else
}//end choose
}//end class Welcome
好厉害的样子