package com.carsystem;
import java.util.*;
public class Main{
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println("欢迎使用租车系统");
System.out.println("是否租车1是0否");
Scanner sc=new Scanner(System.in);
int input=sc.nextInt();
int totalmoney = 0;
//carlist用来存储所有车的资料
Car[] carlist={new Sedan(1,"宝马",1000,4,0),new Sedan(2,"真马",10000,2,0),new Pickup(3,"黄海皮卡",100,4,4),new Pickup(4,"依维柯",7000,12,20)};
if(input==0){
System.out.println("88!");
}else if(input==1){
System.out.println("欢迎您!以下是车源列表(0代表没有此功能)");
System.out.println("序号"+"\t"+"车名"+"\t"+"价钱/天"+"\t"+"载客量"+"\t"+"载货量");
//Car[] carlist={new Sedan(1,"宝马",1000,4,0),new Sedan(2,"真马",10000,2,0),new Pickup(3,"黄海皮卡",100,4,4),new Pickup(4,"依维柯",7000,12,20)};
for(Car ca:carlist){
if(ca instanceof Sedan){
System.out.println(ca.getCarNumb()+"\t"+ca.getCarName()+"\t"+ca.getCarMoney()+"/天"+"\t"+ca.getPassengerNum()+"人"+"\t"+ca.getCarryNum()+"吨");
}
if(ca instanceof Pickup){
System.out.println(ca.getCarNumb()+"\t"+ca.getCarName()+"\t"+ca.getCarMoney()+"/天"+"\t"+ca.getPassengerNum()+"人"+"\t"+ca.getCarryNum()+"吨");
}
}
/*for(int i=0;i<car.length;i++){
System.out.println(car[i]);
car[i].showInfo();
}*/
}
System.out.println("请输入要租车的数量");
int totalNum=sc.nextInt();//存储租车总数//
//if(totalNum==0){
//System.out.println("输入错误重新输入");
while(true){
if(totalNum==0)
{System.out.println("输入有误 重新输入!");
totalNum=sc.nextInt();
//break;
}
else{ break;}
}
for(int j=1;j<=totalNum;j++){
System.out.println("请输入第"+j+"台车序号");
//choicecar用来存储所选择的车信息
Car[] choicecar=new Car[totalNum];
//yourcarnum是用户要租的车序号
int yourcarnum=sc.nextInt();
choicecar[j-1]=carlist[yourcarnum-1];
if(choicecar[j-1] instanceof Sedan){
totalmoney=totalmoney+choicecar[j-1].getCarMoney();
}
if(choicecar[j-1] instanceof Pickup){
totalmoney=totalmoney+choicecar[j-1].getCarMoney();
}
}
System.out.println("请输入想要租车的天数:");
int rentDay = sc.nextInt(); //租车天数
System.out.println("您需要支付总价为:"+totalmoney*rentDay+"元");
}
}
package com.carsystem;
public class Car{
private int carMoney; //汽车租金
private String carName; //汽车名字
private int carNumb; //汽车序列号
private int carryNum; //载货量
private int passengerNum;//载客人数
public int getCarMoney() {
return carMoney;
}
public void setCarMoney(int carMoney) {
this.carMoney = carMoney;
}
public String getCarName() {
return carName;
}
public void setCarName(String carName) {
this.carName = carName;
}
public int getCarNumb() {
return carNumb;
}
public void setCarNumb(int carNumb) {
this.carNumb = carNumb;
}
public int getCarryNum() {
return carryNum;
}
public void setCarryNum(int carryNum) {
this.carryNum = carryNum;
}
public int getPassengerNum() {
return passengerNum;
}
public void setPassengerNum(int passengerNum) {
this.passengerNum = passengerNum;
}
public void showInfo() {
// TODO Auto-generated method stub
}
}