package ToCar;
public class Car {
public String name;//车辆名字
public int number;//车辆序号
public int money;//车辆租金
public int zairen;
public int zaihuo;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getNumber() {
return number;
}
public void setNumber(int number) {
this.number = number;
}
public int getMoney() {
return money;
}
public void setMoney(int money) {
this.money = money;
}
public int getZairen() {
return zairen;
}
public void setZairen(int zairen) {
this.zairen = zairen;
}
public int getZaihuo() {
return zaihuo;
}
public void setZaihuo(int zaihuo) {
this.zaihuo = zaihuo;
}
package ToCar;
public class Passenger extends Car {
public int zairen;
public Passenger(int newNumber,String newName,int newMoney,int newZairen){
number=newNumber;
name=newName;
money=newMoney;
zairen=newZairen;
}
public int getZairen() {
return zairen;
}
public void setZairen(int zairen) {
this.zairen = zairen;
}
}
package ToCar;
public class Pickup extends Car {
public int zairen;
public int zaihuo;
public Pickup(int newNumber,String newName,int newMoney,int newZairen,int newZaihuo){
number=newNumber;
name=newName;
money=newMoney;
zairen=newZairen;
zaihuo=newZaihuo;
}
public int getZairen() {
return zairen;
}
public void setZairen(int zairen) {
this.zairen = zairen;
}
public int getZaihuo() {
return zaihuo;
}
public void setZaihuo(int zaihuo) {
this.zaihuo = zaihuo;
}
}
package ToCar;
public class Truck extends Car {
public int zaihuo;
public Truck(int newNumber,String newName,int newMoney,int newZaihuo){
number=newNumber;
name=newName;
money=newMoney;
zaihuo=newZaihuo;
}
public int getZaihuo() {
return zaihuo;
}
public void setZaihuo(int zaihuo) {
this.zaihuo = zaihuo;
}
}
}
package ToCar;
import java.util.Scanner;
public class Test {
public static void main(String[] args) {
// TODO Auto-generated method stub
Car[] cars={new Passenger(1,"奥迪",500,4),new Pickup(2,"福特皮卡",300,2,50),new Truck(3,"依维柯",600,100)};
System.out.println("欢迎来到您是否要租车:"+"1是"+"\t"+"2否");
Scanner input=new Scanner(System.in);
int shu = input.nextInt();
if(shu==2){
System.out.println("谢谢您的使用再见!");
}
if(shu==1){
System.out.println("你可租的车及价目表:");
System.out.println("序号"+"\t"+"车名"+"\t"+"金额"+"\t"+"载客量/容量");
for(Car car:cars){
if(car instanceof Passenger){
System.out.println(car.getNumber()+"\t"+car.getName()+"\t"+car.getMoney()+"\t"+((Passenger) car).getZairen()+"人");
}
if(car instanceof Pickup){
System.out.println(car.getNumber()+"\t"+car.getName()+"\t"+car.getMoney()+"\t"+((Pickup) car).getZairen()+"人"+"\t"+((Pickup) car).getZaihuo()+"吨");
}
if(car instanceof Truck){
System.out.println(car.getNumber()+"\t"+car.getName()+"\t"+car.getMoney()+"\t"+((Truck) car).getZaihuo()+"吨");
System.out.println("请输入您要租几辆车:");
int zu=input.nextInt();
int p=0;
int q=0;
int s=0;
for(int i =1;i<=zu;i++){
System.out.println("请输入你要选择的第"+i+"辆车:");
Scanner chao=new Scanner(System.in);
int che=input.nextInt();
switch(che){
case 1:p=500+p;
q=4+q;
break;
case 2:p=300+p;
q=2+q;
s=50+s;
break;
case 3:p=600+p;
s=100+s;
}
}
System.out.println("请输入您要租车的天数:");
Scanner zheng=new Scanner(System.in);
int tian = input.nextInt();
tian=tian*p;
System.out.println("总载人数:"+"\n"+q);
System.out.println("总载货量:"+"\n"+s);
System.out.println("租车总金额:"+"\n"+tian);
}
}
}
}
}