继续浏览精彩内容
慕课网APP
程序员的梦工厂
打开
继续
感谢您的支持,我会继续努力的
赞赏金额会直接到老师账户
将二维码发送给自己后长按识别
微信支付
支付宝支付

java嗒嗒租车系统 看别人的例子自己在写的。

慕粉1471701795
关注TA
已关注
手记 1
粉丝 3
获赞 25

package imocc.Project4;

public abstract class Car {
String name; //车的名字
int price; //价格
int flag; //标签号
float peoplevalue; //车载人的人数
float cargovalue; //车载的货物数
public String getName(){
return name;
}
public int getPrice(){
return price;
}
public int getFlag(){
return flag;
}
public float getPeoplevalue(){
return peoplevalue;
}
public float getCargovalue(){
return cargovalue;
}

}

package imocc.Project4;

public class Cartocar extends Car {
public Cartocar(int flag,String name,int price,float cargovalue){
this.flag=flag;
this.name=name;
this.price=price;
this.cargovalue=cargovalue;
}
public int getFlag(){
return flag;
}
public String getName(){
return name;
}
public int getPrice(){
return price;
}
public float getCargovalue(){
return cargovalue;
}
}

package imocc.Project4;

public class Bus extends Car {
public Bus(int flag,String name,int price,float peoplevalue){
this.flag=flag;
this.name=name;
this.price=price;
this.peoplevalue=peoplevalue;
}
public int getFlag(){
return flag;
}
public String getName(){
return name;
}
public int getPrice(){
return price;
}
public float getPeoplevalue(){
return peoplevalue;
}

}

package imocc.Project4;

public class Pickup extends Car {
public Pickup(int flag,String name,int price,float peoplevalue,float cargovalue){
this.flag=flag;
this.name=name;
this.price=price;
this.peoplevalue=peoplevalue;
this.cargovalue=cargovalue;
}
public int getFlag(){
return flag;
}
public String getName(){
return name;
}
public int getPrice(){
return price;
}
public float gerPeoplevalue(){
return peoplevalue;
}
public float getCargovalue(){
return cargovalue;
}
}

package imocc.Project4;
import java.util.Scanner;
public class Test {

public static void main(String[] args) {
System.out.println("******欢迎使用租车系统******");
System.out.println("你是否要选择租车:是 :选择1\t否:选择0");
Scanner input=new Scanner(System.in);
int a=input.nextInt();
 if(a==0){
    System.out.println("欢迎你下次使用");
}
else if(a!=0&&a!=1){
    System.out.println("输入不合法");
}
else if(a==1){
Car[] cars={new Bus(0,"奥迪A6",500,4f),
        new Bus(1,"金龙大巴",2000,20f),
        new Cartocar(2,"擎天柱",2000,20f),
        new Cartocar(3,"霸天虎",1000,10f),
        new Pickup(4,"别克",500,2f,4f),
        new Pickup(5,"长城",1000,2f,8f)};
System.out.println("租车的项目表");
System.out.println("序号\t"+"车型\t"+"价格\t"+"人数");

for(int flag=0;flag<6;flag++){
    if(cars[flag].flag==0cars[flag].flag==1){
        System.out.println(flag+"\t"+cars[flag].name+"\t"+cars[flag].price+"元/天\t载人"+cars[flag].peoplevalue);
    }
    else if(cars[flag].flag==2cars[flag].flag==3){
        System.out.println(flag+"\t"+cars[flag].name+"\t"+cars[flag].price+"元/天\t载货"+cars[flag].cargovalue+"吨");
    }
    else if(cars[flag].flag==4cars[flag].flag==5){
        System.out.println(flag+"\t"+cars[flag].name+"\t"+cars[flag].price+"元/天\t载人"+cars[flag].peoplevalue+"\t载货"+cars[flag].cargovalue+"吨");
    }
}
System.out.println("请输入你租车的数量:");
int num=input.nextInt();
for(int x=0;x<=num;x++){
    System.out.println("请输入第"+(x+1)+"辆车的序号");
    int flag=input.nextInt();
    if(flag<0&&flag>5){
        System.out.println("输入的序号不正确!!!");
    }
    cars[x]=cars[flag];

}
System.out.println("请输入租车的天数");
int day=input.nextInt();
System.out.println("你的账单:");
int price=0;
float peoplevalue=0;
float cargovalue=0;
for(int j=0;j<num;j++){
    if(cars[j] instanceof Bus){
        Bus car=(Bus)cars[j];
        price=price+car.getPrice()*day;
        peoplevalue=peoplevalue+car.getPeoplevalue();
    }
    if(cars[j] instanceof Cartocar){
        Cartocar car=(Cartocar)cars[j];
        price=price+car.getPrice()*day;
        cargovalue=cargovalue+car.getCargovalue();
    }
    if(cars[j]instanceof Pickup){
        Pickup car=(Pickup)cars[j];
        price=price+car.getPrice()*day;
        peoplevalue=peoplevalue+car.getPeoplevalue();
        cargovalue=cargovalue+car.getCargovalue();
    }
    System.out.println("***可载人的车有:");
    if(cars[j] instanceof Bus){
        Bus car=(Bus)cars[j];
        System.out.print(car.getName()+"\t");
    }
    if(cars[j] instanceof Cartocar){
        Cartocar car=(Cartocar)cars[j];
        System.out.print(car.getName()+"\t");
    }
    if(cars[j] instanceof Pickup){
        Pickup car=(Pickup)cars[j];
        System.out.println(car.getName());
    }
    System.out.println("共载人:"+peoplevalue+"人");
    System.out.println("***可载货的车有;");
    if(cars[j] instanceof Cartocar){
        Cartocar car=(Cartocar)cars[j];
        System.out.print(car.getName()+"\t");
    }
    if(cars[j] instanceof Pickup){
        Pickup car=(Pickup)cars[j];
        System.out.println(car.getName());

}
    System.out.println("共载货:"+cargovalue+"吨");
    System.out.println("***租车总价格:"+price+"元");

}
}
}

}

打开App,阅读手记
10人推荐
发表评论
随时随地看视频慕课网APP