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

自己花时间写的JAVA答答租车系统,欢迎讨论

Dva
关注TA
已关注
手记 1
粉丝 4
获赞 42

这是JAVA入门第二季最后的作业。
还有很多可以修改的地方,比如对异常的处理等等。写的比较匆忙,而且第三季还没开始学,所以就先暂时放下了。
以下是代码:

package com.zc;
import java.util.*;
public class initial {
    //导入车辆信息
    public static keChe[] aa={new keChe("斯柯达Yeti",200,5),new keChe("奔驰GLC   ",280,5),new keChe("宝马Z4    ",480,2)};
    public static huoChe[] bb={new huoChe("解放J6P   ",400,6),new huoChe("欧曼GTL   ",420,8),new huoChe("沃尔沃FH16",420,9)};
    public static piKa[] cc={new piKa("风骏5     ",150,2,3),new piKa("福特F650  ",180,2,3)};
    public static Scanner imput=new Scanner(System.in);
    public static void main(String[] args) {
        // 主程序
        System.out.println("=============================================");
        System.out.println("欢迎使用答答租车系统测试版");
        System.out.println("目前可租车辆:");
        System.out.println("====================客车类===================");
        for(int i=0;i<aa.length;i++){
            System.out.println(i+1+"  "+aa[i].getName()+"  租金"+aa[i].getRent()+"/天   可载人"+aa[i].getcargoMen()+"位");
        }
        System.out.println("====================货车类===================");
        for(int i=0;i<bb.length;i++){
            System.out.println(i+1+"  "+bb[i].getName()+"  租金"+bb[i].getRent()+"/天   可载货"+bb[i].getcargoGoods()+"吨");
        }
        System.out.println("====================皮卡类===================");
        for(int i=0;i<cc.length;i++){
            System.out.println(i+1+"  "+cc[i].getName()+"  租金"+cc[i].getRent()+"/天   可载人"+cc[i].getcargoMen()+"位"+"  可载货"+cc[i].getcargoGoods()+"吨");
        }
        System.out.println("=============================================");
        System.out.print("请输入你想租车的辆数:");
        int num=imput.nextInt();
        String[] allName=new String[num];
        int allRent=0;
        int allMen=0;
        double allGoods=0;
        for(int i=1;i<=num;i++){
        System.out.println("请选择你想租的第"+i+"辆车的类型(1.客车 2.货车 3.皮卡)");
        int lei=imput.nextInt();
        switch(lei){
        case 1: 
            System.out.print("请输入你选择的第"+i+"辆车的序号:");
            int a=imput.nextInt();
            System.out.println("你选择的是"+aa[a-1].getName());
            allName[i-1]=aa[a-1].getName();
            allMen+=aa[a-1].getcargoMen();
            allRent+=aa[a-1].getRent();
            break;
        case 2: 
            System.out.print("请输入你选择的第"+i+"辆车的序号:");
            int b=imput.nextInt();
            System.out.println("你选择的是"+bb[b-1].getName());
            allName[i-1]=bb[b-1].getName();
            allGoods+=bb[b-1].getcargoGoods();
            allRent+=bb[b-1].getRent();
            break;
        case 3: 
            System.out.print("请输入你选择的第"+i+"辆车的序号:");
            int c=imput.nextInt();
            System.out.println("你选择的是"+cc[c-1].getName());
            allName[i-1]=cc[c-1].getName();
            allMen+=cc[c-1].getcargoMen();
            allGoods+=cc[c-1].getcargoGoods();
            allRent+=cc[c-1].getRent();
            break;
        default:
            System.out.println("操作出错,请重新进入程序!");
            System.exit(0);
            }
        }
        System.out.println("");
        System.out.println("选择结束====================清单如下");
        System.out.println("===================================");
        System.out.println("选择车辆:");
        System.out.println(Arrays.toString(allName));
        System.out.println("总载人量为"+allMen+"位");
        System.out.println("总载货量为"+allGoods+"吨");
        System.out.println("租车总费用:"+allRent+"元/天");
        System.out.println("===================================");
        System.out.println("=============谢谢使用===============");
    }

}
package com.zc;
//载客车接口
public interface zaiKe {
    void setcargoMen(int cargoMen);
    int getcargoMen();
}
package com.zc;
//载货车接口
public interface zaiHuo {
    void setcargoGoods(double cargoGoods);
    double getcargoGoods();
}
package com.zc;
//父类
public class car {
    public String name;
    public int rent;
    public String getName() {
        return name;
    }
    public int getRent(){
        return rent;    
    }
}
package com.zc;
//客车类
public class keChe extends car implements zaiKe{
    private int cargoMen;
    public keChe(String name,int rent,int cargoMen){
        this.name=name;
        this.rent=rent;
        this.cargoMen=cargoMen;
    }
    public void setcargoMen(int cargoMen){
        this.cargoMen=cargoMen;
    }
    @Override
    public int getcargoMen() {
        return cargoMen;
    }

}
package com.zc;
//货车类
public class huoChe extends car implements zaiHuo{
    public double cargoGoods;
    public huoChe(String name,int rent,double cargoGoods){
        this.name=name;
        this.rent=rent;
        this.cargoGoods=cargoGoods;
    }
    public void setcargoGoods(double cargoGoods){
        this.cargoGoods=cargoGoods;
    }
    @Override
    public double getcargoGoods() {
        return cargoGoods;
    }
}
package com.zc;
//皮卡类
public class piKa extends car implements zaiKe,zaiHuo{
    private int cargoMen;
    private double cargoGoods;
    public piKa(String name,int rent,int cargoMen,double cargoGoods){
        this.name=name;
        this.rent=rent;
        this.cargoMen=cargoMen;
        this.cargoGoods=cargoGoods;
    }
    public void setcargoMen(int cargoMen){
        this.cargoMen=cargoMen;
    }
    public void setcargoGoods(double cargoGoods){
        this.cargoGoods=cargoGoods;
    }
    @Override
    public double getcargoGoods() {
        return cargoGoods;
    }
    @Override
    public int getcargoMen() {
        return cargoMen;
    }

}

下面是运行结果的截图:
运行结果

运行结果


谢谢观看,欢迎讨论!
打开App,阅读手记
24人推荐
发表评论
随时随地看视频慕课网APP

热门评论

很厉害,很清晰明了66666


查看全部评论