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

java第二季。哒哒租车系统(参考的很多前辈们的代码!)

标签:
Java
//主程序
package project1;
import java.util.Scanner; 
public class DaDaZuChe {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
    Car[] car ={ new Car1("奥迪A4",500,4)  ,
                 new Car1("马自达6",400,6) ,
                 new Car3("皮卡雪6",450,4,2),
                 new Car1("金龙",800,20) ,
                 new Car2("松花江",400,4) ,
                 new Car2("依维柯",1000,20)};
    double sum = 0 ;//总租金
    double sum1 = 0 ;//一天的租金 
    int ren = 0 ;//总载客量
    double huo = 0 ;//总载货量
    String keche ="" ; //保存载客车的车名
    String huoche = "" ;//保存货车的车名
     System.out.println("*****欢迎使用哒哒租车系统*****");
     System.out.println("您是否要租车(租车请按1,按其他任意键退出系统)");
     Scanner sc = new Scanner(System.in);
     int a = sc.nextInt();
     if(a != 1){
         System.out.println("系统自爆系统已经启动");
     }else{
         System.out.println("您可租车的类型及价目表:");
         System.out.println("序号"+"\t"+"汽车名称"+"\t  "+"租金"+"\t\t "+"容量");
         for(int i=0;i<car.length;i++){
             System.out.println((i+1)+"\t "+car[i]);
         }

         System.out.println("*****请输入您要租汽车的数量*****");
         int b = sc.nextInt() ;
         Car[] zu = new Car[b] ;
         int[] tian = new int[b] ;
         for(int i=0;i<b;i++){
             System.out.println("请输入您要租的第"+(i+1)+"辆车的序号");
             int c = sc.nextInt();
             zu[i] = car[c-1] ;
             System.out.println(car[c-1]);
             sum1 = sum1+car[c-1].price ;
             System.out.println("请输入您要租几天");
             int d = sc.nextInt() ;
             tian[i] = d ;
             sum =  sum + car[c-1].price*d ;
         }
         System.out.println("您的账单:");
         System.out.println("汽车名称"+"\t       "+"租金"+"\t\t "+"容量"+"\t\t "+"租用天数");
         for ( int i=0;i<zu.length;i++){
             System.out.print(zu[i]);
             System.out.println("\t   "+tian[i]+"天");

             switch(zu[i].name){
             case "奥迪A4" :
                 keche = keche + "奥迪A4" + "   " ;
                 ren = ren + 4 ;
                 break;
             case "马自达6" :
                 keche = keche + "马自达6" + "   " ;
                 ren = ren + 6 ;
                 break;
             case "皮卡雪6" :
                 keche = keche + "皮卡雪6" + "   " ;
                 ren = ren + 4 ;
                 huoche = huoche + "皮卡雪6" + "   " ;
                 huo = huo + 2 ;
                 break;
             case "金龙":
                 keche = keche + "金龙" + "   " ;
                 ren = ren + 20 ;
                 break;
             case "松花江":
                 huoche = huoche + "松花江" + "   " ;
                 huo = huo + 4 ;
                 break;
             case "依维柯":
                 huoche = huoche + "依维柯" + "   " ;
                 huo = huo + 20 ;
                 break;
             }
         }
         System.out.println("载客的汽车:"+keche);
         System.out.println("总的载客量为:"+ren);
         System.out.println("载货的汽车:"+huoche);
         System.out.println("总的载货量为:"+huo);
         System.out.println("一天的租金为:"+sum1);
         System.out.println("总租金为:"+sum);

         }
     }
}

//父类
public class Car {
protected String name ;
protected double price ;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public double getPrice() {
return price;
}
public void setPrice(double price) {
this.price = price;
}
@Override
public String toString() {
return name + "\t " + price+"元/天"+"\t" ;
}

}


//客车类
public class Car1 extends Car {
private int person ;

public int getPeson() {
    return person;
}

public void setPeson(int person) {
    this.person = person;
}

public Car1(){

}

 public Car1(String name,double price,int person){
     this.name = name ;
     this.price = price ;
     this.person = person ;
 }

@Override
public String toString() {
    return   super.toString()+"载人:"+person+"人        " ;
}

}


//货车类
public class Car2 extends Car {
private double goods ;

public double getGoods() {
    return goods;
}

public void setGoods(double goods) {
    this.goods = goods;
}
public Car2(){

}

public Car2(String name,double price,double goods){
    this.name = name ;
    this.price = price ;
    this.goods = goods ;

}

@Override
public String toString() {
    return super.toString() +"载货:"+ goods + "吨";
}

}


//皮卡类
public class Car3 extends Car {
private int person ;
private double goods ;
public int getPerson() {
return person;
}
public void setPerson(int person) {
this.person = person;
}
public double getGoods() {
return goods;
}
public void setGoods(double goods) {
this.goods = goods;
}

public Car3(){

}

public Car3(String name,double price,int person,double goods){
this.name = name ;
this.price = price ;
this.person = person ;
this.goods = goods ;
}
@Override
public String toString() {
return super.toString() +"载人:"+ person + "人/载货:" + goods + "吨";
}

}

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

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

评论

作者其他优质文章

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

100积分直接送

付费专栏免费学

大额优惠券免费领

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

举报

0/150
提交
取消