文章目录
- 任务3
- 【任务3.1】实现日志实体类
- 【任务3.2】创建日志业务类,实现日志信息的采集及打印输出
- 【任务3.3】创建日志测试类,测试任务3.2中的程序,演示日志信息的采集及打印输出
- 任务4
- 【任务4.1】物流实体信息类
- 【任务4.2】创建物流业务类,实现物流信息的采集及打印输出
- 【任务4.3】创建物流测试类,测试任务4.2中的程序,演示物流信息的采集及打印输出
任务3
【任务3.1】实现日志实体类
在com.qst.dms.entity 下创建LogRec.java
功能要求:
- 成员属性如下
// ID标识private int id;// 时间private Date time;// 地点private String address;// 状态private int type;/*** 登录用户名*/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 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;// "保存";
- 构造方法、get/set方法、toString()。
- 实现toArray()方法,将对象的属性数据,转换为字符数组。
程序设计
package com.qst.dms.entity;import java.util.Date;public class LogRec {// ID标识private int id;// 时间private Date time;// 地点private String address;// 状态private int type;/*** 登录用户名*/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 int GATHER = 1;// "采集"public static final int MATCH = 2;// "匹配";public static final int RECORD = 3;// "记录";public static final int SEND = 4;// "发送";public static final int RECEIVE = 5;// "接收";public static final int WRITE = 6;// "归档";public static final int SAVE = 7;// "保存";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) {this.id = id;this.time = time;this.address = address;this.type = type;this.user = user;this.ip = ip;this.logType = logType;}public LogRec() {}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;}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;}@Overridepublic String toString() {return "LogRec:" +"\nid=" + id +"\ntime=" + time +"\naddress='" + address +"\ntype=" + type +"\nuser='" + user +"\nip='" + ip +"\nlogType=" + LogTypeArray[logType] +"\n";}public String[] toArray() {String[] arr = new String[7];arr[0] = String.valueOf(id);arr[1] = String.valueOf(time);arr[2] = address;arr[3] = String.valueOf(type);arr[4] = user;arr[5] = ip;arr[6] = String.valueOf(LogTypeArray[logType]);return arr;}}
【任务3.2】创建日志业务类,实现日志信息的采集及打印输出
在com.qst.dms.service 下创建LogRecService.java
功能要求:
- 实现inputLog方法
public LogRec inputLog() {……}
// 提示用户输入ID标识System.out.println("请输入ID标识:");// 接收键盘输入的整数int id = scanner.nextInt();// 获取当前系统时间Date nowDate = new Date();// 提示用户输入地址System.out.println("请输入地址:");// 接收键盘输入的字符串信息String address = scanner.next();// 数据状态是“采集”int type = LogRec.GATHER;// 提示用户输入登录用户名System.out.println("请输入 登录用户名:");// 接收键盘输入的字符串信息String user = scanner.next();// 提示用户输入主机IPSystem.out.println("请输入 主机IP:");// 接收键盘输入的字符串信息String ip = scanner.next();// 提示用户输入登录状态、登出状态System.out.println("请输入登录状态:1是登录,0是登出");int logType = scanner.nextInt();
在inputLog方法中实现,在控制台模拟接收数据,并返回日志数据对象
- 实现showLog方法,可打印输出日志信息
public void showLog(LogRec... logRecs) {……}
程序设计
package com.qst.dms.service;import com.qst.dms.entity.LogRec;import java.util.Date;
import java.util.Scanner;public class LogRecService {private Scanner scanner;public LogRecService() {scanner = new Scanner(System.in);}public LogRec inputLog() {System.out.println("请输入ID标识:");int id = scanner.nextInt();Date nowDate = new Date();System.out.println("请输入地址:");String address = scanner.next();int type = LogRec.GATHER;System.out.println("请输入登录用户名:");String user = scanner.next();System.out.println("请输入主机IP:");String ip = scanner.next();int logType;while (true) {try {System.out.println("请输入登录状态(1表示登录,0表示登出):");logType = scanner.nextInt();if (logType == 0 || logType == 1) {break;} else {throw new IllegalArgumentException("非法的登录状态");}} catch (Exception e) {System.out.println("输入错误,请重新输入");scanner.nextLine();}}return new LogRec(id, nowDate, address, type, user, ip, logType);}public void showLog(LogRec... logRecs) {System.out.println("日志信息:");for (LogRec logRec : logRecs) {System.out.println(logRec);}}
}
【任务3.3】创建日志测试类,测试任务3.2中的程序,演示日志信息的采集及打印输出
在com.qst.dms.dos 下创建LogRecDemo.java
功能要求:采集2组日志信息,放到数组中,再打印输出
package com.qst.dms.dos;import com.qst.dms.entity.LogRec;
import com.qst.dms.service.LogRecService;public class LogRecDemo {public static void main(String[] args) {LogRecService logRecService = new LogRecService();// 采集日志信息LogRec logRec1 = logRecService.inputLog();LogRec logRec2 = logRecService.inputLog();// 放到数组中LogRec[] logRecArray = {logRec1, logRec2};// 打印输出logRecService.showLog(logRecArray);}
}
测试:
要求全部可能情况都要测一遍
存在哪些可能的bug及修复?
当登陆状态输入非0非1的其他字符时,程序会报错,应该通过异常处理当用户输入非0非1的其他字符时,提醒用户重新输入。
任务4
【任务4.1】物流实体信息类
在com.qst.dms.entity 下创建Transport.java
功能要求:
- 成员属性如下
// ID标识private int id;// 时间private Date time;// 地点private String address;// 状态private int type;/*** 经手人*/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;// 已签收// 状态常量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;// "保存";
- 构造方法、get/set方法、toString()
- 实现toArray()方法,将对象的属性数据,转换为字符数组。
程序设计
package com.qst.dms.entity;import java.util.Date;public class Transport {private int id;private Date time;private String address;private int type;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;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 static final String TransportArray[]=new String[]{null,"SENDDING","TRANSPORTING","RECIEVED"};public Transport() {}public Transport(int id, Date time, String address, int type, String handler, String reciver, int transportType) {this.id = id;this.time = time;this.address = address;this.type = type;this.handler = handler;this.reciver = reciver;this.transportType = transportType;}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;}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;}public String[] toArray() {String[] arr = new String[8];arr[0] = String.valueOf(id);arr[1] = String.valueOf(time);arr[2] = address;arr[3] = String.valueOf(type);arr[4] = handler;arr[5] = reciver;arr[6] = TransportArray[transportType];return arr;}@Overridepublic String toString() {return "Transport:" +"\nid=" + id +"\ntime=" + time +"\naddress=" + address +"\ntype=" + type +"\nhandler=" + handler +"\nreciver=" + reciver +"\ntransportType=" + TransportArray[transportType]+"\n";}
}
【任务4.2】创建物流业务类,实现物流信息的采集及打印输出
在com.qst.dms.service 下创建TransportService.java
功能要求:
- 实现inputTransport方法
public Transport inputTransport() {……
}
在inputTransport方法中实现,在控制台模拟接收数据,并返回物流数据
// 提示用户输入ID标识System.out.println("请输入ID标识:");// 接收键盘输入的整数int id = scanner.nextInt();// 获取当前系统时间Date nowDate = new Date();// 提示用户输入地址System.out.println("请输入地址:");// 接收键盘输入的字符串信息String address = scanner.next();// 数据状态是“采集”int type = Transport.GATHER;// 提示用户输入登录用户名System.out.println("请输入货物经手人:");// 接收键盘输入的字符串信息String handler = scanner.next();// 提示用户输入主机IPSystem.out.println("请输入 收货人:");// 接收键盘输入的字符串信息String reciver = scanner.next();// 提示用于输入物流状态System.out.println("请输入物流状态:1发货中,2送货中,3已签收");// 接收物流状态int transportType = scanner.nextInt();
- 实现showTransport方法,可打印输出物流信息
public void showTransport(Transport... transports) {……
}
程序设计
package com.qst.dms.service;import com.qst.dms.entity.Transport;import java.util.Date;
import java.util.Scanner;public class TransportService {private Scanner scanner;public TransportService() {scanner = new Scanner(System.in);}public Transport inputTransport() {System.out.println("请输入ID标识:");int id = scanner.nextInt();Date nowDate = new Date();System.out.println("请输入地址:");String address = scanner.next();int type = Transport.GATHER;System.out.println("请输入货物经手人:");String handler = scanner.next();System.out.println("请输入收货人:");String reciver = scanner.next();int transportType;while (true) {try {System.out.println("请输入物流状态(1表示发货中,2表示送货中,3表示已签收):");transportType = scanner.nextInt();if (transportType ==1 || transportType == 2 || transportType==3) {break;} else {throw new IllegalArgumentException("非法的物流状态");}} catch (Exception e) {System.out.println("输入错误,请重新输入");scanner.nextLine();}}return new Transport(id, nowDate, address, type, handler, reciver, transportType);}public void showTransport(Transport... transports) {System.out.println("物流信息:");for (Transport transport : transports) {System.out.println(transport);}}
}
【任务4.3】创建物流测试类,测试任务4.2中的程序,演示物流信息的采集及打印输出
在com.qst.dms.dos 下创建TransportDemo.java
功能要求:采集2组物流信息,放到数组中,再打印输出
package com.qst.dms.dos;import com.qst.dms.entity.Transport;
import com.qst.dms.service.TransportService;public class TransportDemo {public static void main(String[] args) {TransportService transportService = new TransportService();// 采集物流信息Transport transport1 = transportService.inputTransport();Transport transport2 = transportService.inputTransport();// 放到数组中Transport[] transportArray = {transport1, transport2};// 打印输出transportService.showTransport(transportArray);}
}
测试:
要求全部可能情况都要测一遍
存在哪些可能的bug及修复?
当物流状态输入非1非2非3的其他字符时,程序会报错,应该通过异常处理当用户输入非1非2非3的其他字符时,提醒用户重新输入。