博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
JavaOO练习:违规管理系统
阅读量:6943 次
发布时间:2019-06-27

本文共 4359 字,大约阅读时间需要 14 分钟。

为交管局设计一个违规管理系统;要求记录违规车辆,驾驶员,处理交警信息; 分析: 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+"\n驾驶证:"                     +this.drivingLicence+"\n驾驶员:"+this.driver+"\n驾照分:"+this.score+"\n罚金:"+this.money+"\n驾照作废,请重新学习";         }         return "车辆型号:"+this.carName+"\n驾驶证:"                 +this.drivingLicence+"\n驾驶员:"+this.driver+"\n驾照分:"+this.score+"\n罚金:"+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

你可能感兴趣的文章
centos6配置固定ip地址(选择桥接模式)
查看>>
Lattice 开发工具Diamond 相关版本下载地址
查看>>
细聊MySQL的分区功能
查看>>
2017 年 机器学习之数据挖据、数据分析,可视化,ML,DL,NLP等知识记录和总结
查看>>
Java 测试驱动开发--“井字游戏” 游戏实战
查看>>
【Scala】Scala-循环与遍历
查看>>
为何在查询中索引未被使用 (Doc ID 1549181.1)
查看>>
安全之初——加解密、签名和证书理解
查看>>
【视频教程】一步步将AppBox升级到Pro版
查看>>
QNX多线程同步之Barrier(屏障)
查看>>
用Lua定制Redis命令
查看>>
使用MSTest进行单元测试
查看>>
SQL Server使用侦听器IP访问时遇到"The target principal name is incorrect. Cannot generate SSPI context"...
查看>>
Linux内核配置解析 - Boot options
查看>>
贝叶斯学习及共轭先验
查看>>
前端页面性能优化的几种方式
查看>>
Windows下安装Redis并注册为服务
查看>>
【BIEE】18_时间序列函数的使用
查看>>
从 HelloWorld 看 Java 字节码文件结构
查看>>
使用X.509数字证书加密解密实务(一)-- 证书的获得和管理
查看>>