【技能实训】DMS数据挖掘项目-Day03

任务5

【任务5.1】基础信息实体类

在com.qst.dms.entity 下创建DataBase.java

功能要求:

  1. 成员属性如下
    // ID标识
	private int id;
	// 时间
	private Date time;
	// 地点
	private String address;
	// 状态
	private int type;
	// 状态常量
	public static final int GATHER=1;//"采集"
	public static final int MATHCH=2;//"匹配";
	public static final int RECORD=3;//"记录";
	public static final int SEND=4;//"发送";
	public static final int RECIVE=5;//"接收";
	public static final int WRITE=6;//"归档";
	public static final int SAVE=7;//"保存";

  1. 构造方法、get/set方法、toString()

程序设计

package com.qst.dms.entity;

import java.util.Date;

public class DataBase {
    
    
    // ID标识
    private int id;
    // 时间
    private Date time;
    // 地点
    private String address;
    // 状态
    private int type;
    // 状态常量
    public static final int GATHER = 1;//"采集"
    public static final int MATHCH = 2;//"匹配";
    public static final int RECORD = 3;//"记录";
    public static final int SEND = 4;//"发送";
    public static final int RECIVE = 5;//"接收";
    public static final int WRITE = 6;//"归档";
    public static final int SAVE = 7;//"保存";

    public DataBase(int id, Date time, String address, int type) {
    
    
        this.id = id;
        this.time = time;
        this.address = address;
        this.type = type;
    }

    public int getId() {
    
    
        return id;
    }

    public void setId(int id) {
    
    
        this.id = id;
    }

    public Date getTime() {
    
    
        return time;
    }

    public void setTime(Date time) {
    
    
        this.time = time;
    }

    public String getAddress() {
    
    
        return address;
    }

    public void setAddress(String address) {
    
    
        this.address = address;
    }

    public int getType() {
    
    
        return type;
    }

    public void setType(int type) {
    
    
        this.type = type;
    }

    @Override
    public String toString() {
    
    
        return  "\nid=" + id +
                "\ntime=" + time +
                "\naddress=" + address +
                "\ntype=" + type
                ;
    }
}

【任务5.2.1】继承DataBase类,重构日志类

在com.qst.dms.entity 重写 LogRec.java

功能要求:

  1. 成员属性如下
    /**
	 *  登录用户名
	 */
	private String user;
	/**
	 * 登录用户主机IP地址
	 */
	private String ip;
	/**
	 * 登录状态:登录、登出
	 */
	private int logType;
	/**
	 * 登录常量LOG_IN、登出常量常量LOG_OUT
	 */
    public static final int LOG_IN=1;
    public static final int LOG_OUT=0;
  1. 构造方法、get/set方法、toString()
  2. 实现toArray()方法,将对象的属性数据,转换为字符数组。

程序设计

package com.qst.dms.entity;

import java.util.Date;

public class LogRec extends DataBase {
    
    
    /**
     *  登录用户名
     */
    private String user;
    /**
     * 登录用户主机IP地址
     */
    private String ip;
    /**
     * 登录状态:登录、登出
     */
    private int logType;
    /**
     * 登录常量LOG_IN、登出常量常量LOG_OUT
     */
    public static final int LOG_IN=1;
    public static final int LOG_OUT=0;
    public static final String LogTypeArray[]=new String[]{
    
    
            "LogOut",
            "LogIn"
    };

    public LogRec(int id, Date time, String address, int type, String user, String ip, int logType) {
    
    
        super(id, time, address, type);
        this.user = user;
        this.ip = ip;
        this.logType = logType;
    }

    public String getUser() {
    
    
        return user;
    }

    public void setUser(String user) {
    
    
        this.user = user;
    }

    public String getIp() {
    
    
        return ip;
    }

    public void setIp(String ip) {
    
    
        this.ip = ip;
    }

    public int getLogType() {
    
    
        return logType;
    }

    public void setLogType(int logType) {
    
    
        this.logType = logType;
    }

    @Override
    public String toString() {
    
    
        return  "LogRec: " +
                super.toString() +
                "\nuser=" + user +
                "\nip=" + ip +
                "\nlogType=" + LogTypeArray[logType] +
                "\n";
    }

    public char[] toArray() {
    
    
        String data = this.getId() + "," + this.getTime().getTime() + "," + this.getAddress() + "," + this.getType() + "," + this.getUser() + "," + this.getIp() + "," + LogTypeArray[this.getLogType()];
        return data.toCharArray();
    }
}

【任务5.2.2】继承DataBase类,重构物流实体类

在com.qst.dms.entity 重写 Transport.java

功能要求:

  1. 成员属性如下
    /**
	 * 经手人
	 */
	private String handler;
	/**
	 * 收货人
	 */
	private String reciver;
	/**
	 * 物流状态
	 */
	private int transportType;
	/**
	 * 物流状态常量:发货中, 送货中, 已签收
	 */
	public static final int SENDDING = 1;// 发货中
	public static final int TRANSPORTING = 2;// 送货中
	public static final int RECIEVED = 3;// 已签收
  1. 构造方法、get/set方法、toString()
  2. 实现toArray()方法,将对象的属性数据,转换为字符数组。

程序设计

package com.qst.dms.entity;

import java.util.Date;

public class Transport extends DataBase {
    
    
    /**
     * 经手人
     */
    private String handler;
    /**
     * 收货人
     */
    private String reciver;
    /**
     * 物流状态
     */
    private int transportType;
    /**
     * 物流状态常量:发货中, 送货中, 已签收
     */
    public static final int SENDING = 1;// 发货中
    public static final int TRANSPORTING = 2;// 送货中
    public static final int RECEIVED = 3;// 已签收
    public static final String TransportArray[]=new String[]{
    
    
            null,
            "SENDDING",
            "TRANSPORTING",
            "RECIEVED"
    };

    public Transport(int id, Date time, String address, int type, String handler, String reciver, int transportType) {
    
    
        super(id, time, address, type);
        this.handler = handler;
        this.reciver = reciver;
        this.transportType = transportType;
    }

    public String getHandler() {
    
    
        return handler;
    }

    public void setHandler(String handler) {
    
    
        this.handler = handler;
    }

    public String getReciver() {
    
    
        return reciver;
    }

    public void setReciver(String reciver) {
    
    
        this.reciver = reciver;
    }

    public int getTransportType() {
    
    
        return transportType;
    }

    public void setTransportType(int transportType) {
    
    
        this.transportType = transportType;
    }

    @Override
    public String toString() {
    
    
        return  "Transport: " +
                super.toString() +
                "\nhandler=" + handler +
                "\nreciver=" + reciver +
                "\ntransportType=" + TransportArray[transportType] +
                "\n";
    }

    public char[] toArray() {
    
    
        String data = this.getId() + "," + this.getTime().getTime() + "," + this.getAddress() + "," + this.getType() + "," + this.getHandler() + "," + this.getReciver() + "," + TransportArray[this.getTransportType()];
        return data.toCharArray();
    }
}

【任务5.2.3】创建物流、日志测试类,测试任务5.2中的程序,演示物流信息、日志信息的采集及打印输出

在com.qst.dms.dos 下创建EntityDataDemo.java

功能要求:采集2组物流信息、2组日志信息,放到数组中,再打印输出

程序设计

package com.qst.dms.dos;

import com.qst.dms.entity.LogRec;
import com.qst.dms.entity.Transport;
import com.qst.dms.service.LogRecService;
import com.qst.dms.service.TransportService;

public class EntityDataDemo {
    
    
    public static void main(String[] args) {
    
    

        LogRecService logRecService = new LogRecService();
        TransportService transportService = new TransportService();

        // 采集日志信息
        LogRec logRec1 = logRecService.inputLog();
        LogRec logRec2 = logRecService.inputLog();

        // 放到数组中
        LogRec[] logRecArray = {
    
    logRec1, logRec2};

        // 打印输出
        logRecService.showLog(logRecArray);

        // 采集物流信息
        Transport transport1 = transportService.inputTransport();
        Transport transport2 = transportService.inputTransport();

        // 放到数组中
        Transport[] transportArray = {
    
    transport1, transport2};

        // 打印输出
        transportService.showTransport(transportArray);
    }
}

测试:
要求全部可能情况都要测一遍

1

存在哪些可能的bug及修复?

当输入非法字符时会报错,可以添加异常处理,提示用户重新输入。

猜你喜欢

转载自blog.csdn.net/m0_68111267/article/details/131516463
今日推荐