汽车租赁系统(初识面向对象):

汽车租赁系统(初识面向对象):

在这里插入图片描述

1.父类:

package project.cartwo;

public class Car {
    public int serial;//车编号
    public String brand;//品牌
    public String plate;//车牌
    public double addr;//日租金
    public int seating;//座位数
    public int type;//车型
    public int status;//车状态
    public Car(){

    }
    /*
    构造方法的重载
     */
    //轿车调用该参数,少一个座位数,分别为品牌,日租金,车牌,车型,车状态,车编号。
    public Car(String brand, double addr, String plate,int type,int status,int serial) {
        this.brand = brand;
        this.plate = plate;
        this.addr = addr;
        this.type=type;
        this.status=status;
        this.serial=serial;
    }
    // 客车调用该参数,分别为品牌,日租金,车牌,座位数,车型,车状态,车编号。
    public Car(String brand, String plate, double addr, int seating,int type,int status,int serial) {
        this.brand = brand;
        this.plate = plate;
        this.addr = addr;
        this.seating = seating;
        this.type=type;
        this.status=status;
        this.serial=serial;
    }
    public double discount(double day,int addr){//定义折扣的方法,用于子类重写

        return 0.0;
    }
}

2.子类继承,重写方法

package project.cartwo;

public class PassengerCar extends Car{
    //调用父类构造方法
    public PassengerCar(String brand, String plate, double addr,int seating,int type,int status,int serial) {
        super( brand, plate, addr,seating,type ,status,serial);
    }
    public PassengerCar(){

    }
    @Override//客车折扣重写
    public double discount(double day, int addr) {//传入租用天数,和日租金,算出总价,重写父类方法
        double money;
        if (day >= 3 && day <7) {
            money = addr * 0.9 * day;
        } else if (day >=7 && day <30) {
            money = addr * 0.8 * day;
        } else if (day >= 30&&day<150) {
            money= addr * 0.7 * day;
        } else if(day>150){
            money = addr * 0.6 * day;
        }else {
           money=addr*day;
        }
        return money;
    }
}
====================================================
    package project.cartwo;

/**
 * 客车
 */
public class Limousine extends Car  {
    //调用父类构造方法
    public Limousine(String brand, String plate, double addr ,int type,int status,int serial) {
        super( brand, addr, plate, type ,status,serial);
    }
    public Limousine(){//构建无参构造,便于创建该对象
        super();
    }
    @Override//轿车折扣重写
    public double discount(double day, int addr) {//传入租用天数,和日租金,算出总价,重写父类方法
       double money;
        if (day > 7 && day <= 30) {
            money = addr * 0.9 * day;
        } else if (day > 30 && day <= 150) {
            money =addr * 0.8 * day;
        } else if (day >= 150) {
            money = addr * 0.7 * day;
        } else {
           money=addr*day;
        }
        return money;
    }
}

3.静态方法:

package project.cartwo;


import java.util.Scanner;

public class Comments {
    public  static  boolean juge=true;
    public static Car garage[]=new Car[100];//创建静态车类数组
    public static  void  creat() {//定义静态方法,传入Car对象,创建车库
        Limousine L1 = new Limousine( "宝马X6", "京NY28588", 800, 0 ,0,1);
        Limousine L2 = new Limousine( "宝马550i", "京CNY3284", 600, 0 ,0,2);
        Limousine L3 = new Limousine( "别克林荫", "京NT37465", 300, 0 ,0,3);
        Limousine L4 = new Limousine( "别克GL8", "京NT96968", 600, 0 ,0,4);

        PassengerCar p1 = new PassengerCar( "金龙", "京8696997", 1500, 16, 1, 0, 1 );
        PassengerCar p2 = new PassengerCar( "金杯", "京9696996", 1500, 34, 1,0,2);
        PassengerCar p3 = new PassengerCar( "金龙", "京8696998", 1500, 34, 1 ,0,3);
        garage[0] = L1;
        garage[1] = L2;
        garage[2] = L3;
        garage[3] = L4;
        garage[4] = p1;
        garage[5] = p2;
        garage[6] = p3;
    }//创建车库
    ========================================
    public static void usedSelect(){
        boolean j = Comments.juge;
        Scanner scanner = new Scanner( System.in );
        System.out.println( "===========欢迎来到汽车租聘系统==============" );
        Comments.creat();//调用静态方法,创建车库
        while (j) {
            System.out.println( "=======请选择您要选择的汽车种类:1.轿车 2.客车 3.退出" );
            System.out.println( "                                             " );
            System.out.println( "请输入您要选择的汽车种类:" );
            int kind = scanner.nextInt();//选择汽车种类
            switch (kind) {
                case 1:
                    Comments.selectKind( 0 );
                    j=false;
                    break;
                case 2:
                    Comments.selectKind( 1 );
                    j=false;
                    break;
                case 3:
                    System.out.println("欢迎您下次使用!!");
                    j=false;//利用监管者退出系统
                    break;
                default:
                    System.out.println( "输入有误请重新输入" );
                    break;
            }

        }
    }//客户进入系统,打印车库
    ===========================================
    public static void show(int type) {//判断该车是否已出租
        for (int i = 0; i <7 ; i++) {//循环遍历
            //选择判断用户选择的汽车种类,并判断该车是否出租已
            if (garage[i].type == type && garage[i].status==0) {
                if(type==0){//轿车展示
                    System.out.println(  garage[i].serial + "\t\t" +garage[i].brand + "\t\t" + garage[i].plate + "\t\t" + garage[i].addr  );
                }else if(type==1)//客车展示
                System.out.println( "\t"+garage[i].serial + "\t\t"+ garage[i].brand + "\t\t" + garage[i].plate + "\t\t" + garage[i].addr + "\t\t" + garage[i].seating );
            }
        }
    }//判断该车是否已出租
    ======================================
    public static void selectLimousine(){
        Scanner scanner = new Scanner( System.in );
        System.out.println("请输入您要选择的车辆编号:");
        int serial = scanner.nextInt();
        garage[serial-1].status=1;//通过车的编号,确定数组下标
        System.out.println("请输入您要租用的天数:");
        double days = scanner.nextInt();
        Limousine limousine = new Limousine();//创建对象,调用该类的静态方法
        printCar( serial-1,days );//调用上边两个方法
        System.out.print(limousine.discount( days, (int) garage[serial-1].addr ));
    }//客户选择轿车
    ==================================================
    public static void selectPassenger(){//客户选择方法
        Scanner scanner = new Scanner( System.in );
        System.out.println("请输入您要选择的车辆编号:");
        int serial = scanner.nextInt();
        garage[serial+3].status=1;//通过车的编号,确定数组下标
        System.out.println("请输入您要租用的天数:");
        double days = scanner.nextInt();
        PassengerCar passengerCar = new PassengerCar();
        printCar( serial+3,days );//调用上边两个方法
        System.out.print(passengerCar.discount( days, (int) garage[serial+3].addr ));

    }//客户选择客车
    ============================================
    public static void printCar(int V,double day){//打印客户订单信息
        System.out.println( "您选购的轿车订单如下:" );
        System.out.println( "品牌:   " + "   车牌号:" );
        System.out.println( garage[V].brand + "\t\t" + garage[V].plate+"\t\t"
        );
        System.out.println( "总价格:");
    }//打印客户订单信息
    ==============================================
    public static void selectKind(int type){
        Scanner scanner = new Scanner( System.in );
        while (juge) {
            System.out.println( "=====汽车种类如下=====:" );
            System.out.println( "编号:   " + "品牌:   " + "   车牌号:" + "    日租价格:" );
            Comments.show( type );//调用静态方法,展示轿车车库
            if (type == 0) {
                Comments.selectLimousine();//调用选轿车的方法
            } else {
                selectPassenger();
            }
            System.out.println( "=====>是否要继续选购:1.是 2.否" );
            int i = scanner.nextInt();//是否要继续选购
            if (i == 1) {//监管者
                juge = true;
            } else if (i == 2) {
                juge = false;
                System.out.println( "欢迎下次使用!!" );

            }
        }


    }//客户是否选择多次购买
    }


4.系统入口:

package project.Text;


import project.cartwo.Comments;

public class StartText {
    public static void main(String[] args) {
        Comments.usedSelect();
    }
    }


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值