package Transport;
public class Car{
String name;//车名
int price;//价格
int pNum;//载人数
int load;//载重
}
class Truck extends Car{ //载货车
Truck(String name,int price,int load){
this.name=name;
this.price=price;
this.load=load;
}
}
class Mannedcar extends Car{ //载人车
Mannedcar(String name,int price,int pNum){
this.name=name;
this.price=price;
this.pNum=pNum;
}
}
class Pickup extends Car{ //既能载人又能载货
Pickup(String name,int price,int pNum,int load){
this.name=name;
this.price=price;
this.pNum=pNum;
this.load=load;
}
}
package Transport;
import java.util.;
public class test{
static Scanner input=new Scanner (System.in);
static Car[] cars={new Mannedcar("奥迪A4",500,4),new Mannedcar("马自达",400,4),new Pickup("皮卡雪",450,2,4),new Mannedcar("金龙",800,20),new Truck("松花江",400,4), new Truck("依维柯",1000,20)};
public static void main(String[] args)
{
int num;
System.out.println("欢迎使用答答租车系统");
System.out.println("您是否需要租车 :1 是 0 否");
int select =input.nextInt();
if(select==0)
{
input.close();
System.exit(-1);
}
//车量信息显示
System.out.println("可租车型信息");
for(int i=0;i<6;i++)
System.out.println(i+1+"."+cars[i].name+"\t"+cars[i].price+"/天"+"\t"+"载人:"+cars[i].pNum+"人"+" "+"载货:"+cars[i].load+"T");
//选择车辆
do
{
System.out.println("请输入想要租的车辆序号:");
num=input.nextInt();
}
while(num<1||num>6);
//选择数量天数
System.out.println("请输入租车数量:");
int carNum =input.nextInt();
System.out.println("请输入租车天数");
int days=input.nextInt();
int price=cars[num-1].pricecarNum*days;
System.out.println("您所选择的车型为:"+cars[num-1].name);
System.out.println("总载货量:"+cars[num-1].load*carNum+"\n"+"总载人数:"+cars[num-1].pNum*carNum+"\n"+"时间:"+days+"天");
System.out.println("您需要支付金额:"+price+"元");
}
}