JavaOO练习:违规管理系统

为交管局设计一个违规管理系统;要求记录违规车辆,驾驶员,处理交警信息;
分析:
1、对象:车辆、车辆型号、驾驶证、驾驶证分、车主姓名、罚款、驾驶证状态、扣分、违规
2、抽类:
TrafficControl交通管理类: 闯红灯扣分、罚款;乱停车扣分、罚款;超速扣分、罚款;未系安全带扣分、罚款;(后期可增加)
CarInformation车辆信息类: 属性:车辆型号、驾驶证、驾驶证分、车主姓名、罚款、驾驶证状态(车牌号待加入); 方法:查询车辆信息状态,判断驾驶证状态
interface接口TrafficRegulations违章:闯红灯,超速,乱停,未系安全带(。。。。可继续增加)



package com.lovo.violationManagementSystem.bean; /**
 * 定义一个标准:违章
 * @author 侯熙
 * @version 1.0
 * @since jdk1.8.0_25
 */ public interface TrafficRegulations { /** * 闯红灯 */ public void runRedLights(); /** * 超速 * @param speed 当前速度 * @param limitedSpeed 限定速度 */ public void overSpeed(double speed,double limitedSpeed); /** * 违章停车 */ public void illegalParking(); /** * 未系安全带 */ public void fastenSeatBelt(); } package com.lovo.violationManagementSystem.bean; /**
 * 交通管理
 * @author 侯熙
 * @version 1.0
 * @since jdk1.8.0_25
 */ public class TrafficControl extends CarInformation implements TrafficRegulations{ /** * 闯红灯扣分 */ static final int RUN_RED_LIGHTS_SCORE = -6; /** * 闯红灯罚款 */ static final int RUN_RED_LIGHTS_MONEY = -200; /** * 违规停车罚款 */ static final int ILLEGAL_PARKING_MONEY = -200; /** * 未系安全带扣分 */ static final int FASTE_NSEAT_BELT_SCORE = -2; /** * 未系安全带罚款 */ static final int FASTE_NSEAT_BELT_MONEY = -200; private int overSpeedScore;//超速扣分 private int overSpeedMoney;//超速罚款 /** * 构造方法 * @param carName 车辆型号 * @param drivingLicence 驾驶证信息 * @param driver 驾驶员姓名 */ public TrafficControl(String carName, int drivingLicence, String driver) { super(carName, drivingLicence, driver); // TODO Auto-generated constructor stub } @Override public void runRedLights() { // TODO Auto-generated method stub this.score += RUN_RED_LIGHTS_SCORE; this.money += RUN_RED_LIGHTS_MONEY; } @Override public void overSpeed(double speed,double limitedSpeed) { // TODO Auto-generated method stub if (speed > limitedSpeed*(1+0.5)) { this.overSpeedScore = -12; this.overSpeedMoney = -2000; }else if (speed > limitedSpeed*(1+0.2)) { this.overSpeedScore = -6; this.overSpeedMoney = -200; }else if (speed > limitedSpeed) { this.overSpeedScore = -3; this.overSpeedMoney = -200; }else{ this.overSpeedScore = 0; this.overSpeedMoney = 0; } this.score += this.overSpeedScore; this.money += this.overSpeedMoney; } @Override public void illegalParking() { // TODO Auto-generated method stub this.money += ILLEGAL_PARKING_MONEY; } @Override public void fastenSeatBelt() { // TODO Auto-generated method stub this.score += FASTE_NSEAT_BELT_SCORE; this.money += FASTE_NSEAT_BELT_MONEY; } } package com.lovo.violationManagementSystem.bean;
/**
 * 车辆信息
 * @author 侯熙
 * @version 1.0
 * @since jdk1.8.0_25
 */
public class CarInformation {
    private String carName;
    private int drivingLicence;
    private String driver;
    protected int score = 12;
    protected int money = 0;
    protected boolean status;
    /**
     * 构造方法
     * @param carName 车辆型号
     * @param drivingLicence 驾驶证信息
     * @param driver 驾驶员姓名
     */
    CarInformation(String carName,int drivingLicence,String driver){
        this.carName = carName;
        this.drivingLicence = drivingLicence;
        this.driver = driver;
    }
    /**
     * 重写to.String 输出车辆信息
     */
    public String toString(){
        if(setStatus()){
            return "车辆型号:"+this.carName+" 驾驶证:"
                    +this.drivingLicence+" 驾驶员:"+this.driver+" 驾照分:"+this.score+" 罚金:"+this.money+" 驾照作废,请重新学习";
        }
        return "车辆型号:"+this.carName+" 驾驶证:"
                +this.drivingLicence+" 驾驶员:"+this.driver+" 驾照分:"+this.score+" 罚金:"+this.money;
    }
    /**
     * 查询驾驶证是否有效,无效为true
     * @return
     */
    public boolean getStatus() {
        return status;
    }
    /**
     * 判断驾驶证是否有效
     * @return 有效为false,无效为true
     */
    public boolean setStatus() {
        if(score <= 0){
            this.status = true;
        }
        return this.status;
    }
}

package com.lovo.violationManagementSystem.test; import com.lovo.violationManagementSystem.bean.TrafficControl; public class Test { public static void main(String[] args) { TrafficControl[] tra =new TrafficControl[4]; tra[0]= new TrafficControl("A8", 46546546, "li4"); tra[0].runRedLights(); tra[0].fastenSeatBelt(); System.out.println(tra[0]); tra[0].overSpeed(120, 80); System.out.println(tra[0]); } }
原文地址:https://www.cnblogs.com/houxi1234/p/6380343.html