为了账号安全,请及时绑定邮箱和手机立即绑定

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

标签:
Java

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+"元");

}
}
}

}

点击查看更多内容
10人点赞

若觉得本文不错,就分享一下吧!

评论

作者其他优质文章

正在加载中
感谢您的支持,我会继续努力的~
扫码打赏,你说多少就多少
赞赏金额会直接到老师账户
支付方式
打开微信扫一扫,即可进行扫码打赏哦
今天注册有机会得

100积分直接送

付费专栏免费学

大额优惠券免费领

立即参与 放弃机会
意见反馈 帮助中心 APP下载
官方微信

举报

0/150
提交
取消