java 考勤系统

wqj1993 2014-12-28 01:38:59
考勤系统功能说明:
1、in.txt中存储员工的刷卡记录,格式:ID,NAME,TIME(半角逗号分隔),举例如下:
·
22,yangxi,07:23
22,yangxi,10:48
1)最少有1条记录,最多有50条记录;
2)最多有10个员工的刷卡记录
3)员工的名字最长为10个英文字符
4)每个员工最多可能有5条记录
5)记录没有时间先后顺序,也没有ID前后顺序
6)ID的范围是1~1000
2、规定上班时间为8:00~17:30,所有刷卡时间精确到分;
3、考勤类型分为“NORMAL(正常)、ABSENT(旷工)、WORK LATE(迟到)、LEAVE EARLY(早退)、WORK LATE&LEAVE EARLY(既迟到又早退),PUNCH ABNORMAL(刷卡异常)”:
1)NORMAL(正常):至少两次刷卡,最早的刷卡时间早于8:00(注意:8:00刷卡算迟到),且最晚的刷卡时间晚于17:30(注意:17:30刷卡算早退);
2)ABSENT(旷工):至少两次刷卡,有两种情况记为旷工:a、最早的刷卡时间晚于17:30;b、最晚的刷卡时间早于8:00;
3)WORK LATE(迟到):至少两次刷卡,最早的刷卡时间晚于8:00,且最晚的刷卡时间晚于17:30;
4)LEAVE EARLY(早退):至少两次刷卡,最早的刷卡时间早于8:00,且最晚的刷卡时间早于17:30;
5)WORK LATE&LEAVE EARLY(既迟到又早退):至少两次刷卡,最早的刷卡时间晚于8:00,且最晚的刷卡时间早于17:30;
6)PUNCH ABNORMAL(刷卡异常):只有1次刷卡记录;
4、工时计算方法:最晚的刷卡时间-最早的刷卡时间,有以下几种情况:
1)旷工的情况下,工时记为0;
2)刷卡异常的情况下,工时记为0。
5、输出到out.txt当中,输出格式如下:
ID = 5
NAME = zhangting
TYPE = WORK LATE
CHECK IN = 09:15
CHECK OUT = 19:15
WORK TIME = 10H0M

ID = 9
NAME = zhanglei
TYPE = WORK LATE&LEAVE EARLY
CHECK IN = 08:30
CHECK OUT = 17:29
WORK TIME = 8H59M
输出有如下要求:
1) 每个记录中间使用一个空行分隔,最后一条记录后面没有空行;
2)CHECK IN为最早刷卡的时间
3)CHECK OUT为最晚刷卡的时间
4)如果1次刷卡记录,则CHECK OUT后面为空
5)如果工时为0,则为0H0M
6)需要按照ID排序,从小到大输出
...全文
483 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
wqj1993 2014-12-28
  • 打赏
  • 举报
回复
引用 8 楼 guest6379 的回复:
huawei的面试题?这工程是什么意思?需求功能是什么?完整吗? 如果要分享项目请到 http://code.csdn.net
需求在一楼。代码是原工程,没有具体实现,只需要在demo里面写出函数实现就好,demotest是测试用例。 这题我做了10+个小时才做出来,我想来跟大家交流一下,找找自己不足。
guest6379 2014-12-28
  • 打赏
  • 举报
回复
huawei的面试题?这工程是什么意思?需求功能是什么?完整吗? 如果要分享项目请到 http://code.csdn.net
wqj1993 2014-12-28
  • 打赏
  • 举报
回复
package testcase;


import huawei.Demo;
import junit.framework.TestCase;














import java.io.*;
import java.util.Vector;


public class DemoTest extends TestCase {
private Demo demo;
private final static String USER_DIR = System.getProperty("user.dir");
private final static String TEST_FOLDER_PATH = USER_DIR + "\\testCase\\";
private final static String TEST_FOLDER_TARGET = TEST_FOLDER_PATH + "target\\";




public void setUp() {
demo = new Demo();
}


private Vector<String> readOutputFile(String filePath) {
Vector<String> vector = new Vector<String>();
try {
FileInputStream fs = new FileInputStream(filePath);
InputStreamReader isr = new InputStreamReader(fs);
BufferedReader br = new BufferedReader(isr);


String data = "";
while ((data = br.readLine()) != null) {
if (data.length() == 0) {
continue;
}
vector.add(data);
}
} catch (FileNotFoundException e) {
throw new RuntimeException("文件路径错误!");
} catch (IOException e) {
throw new RuntimeException("文件读取失败!");
}
return vector;
}


private boolean isSame(String output, String targetPath) {
Vector<String> vector = this.readOutputFile(output);
Vector<String> tgVector = this.readOutputFile(targetPath);


if (vector.size() != tgVector.size()) {
return false;
}
for (int i = 0; i < vector.size(); i++) {
if (!vector.get(i).equals(tgVector.get(i))) {
return false;
}
}
return true;
}


private void testcaseHelper_Should_Fail(String inFilePath, String outFilePath) {
try {
boolean result = demo.attandentSystem(inFilePath, outFilePath);
assertFalse(result);
} catch (Exception e) {
assertTrue(true);
}
}


private void testcaseHelper_Should_Success(String inFilePath, String outFilePath, String targetPath) {
try {
boolean result = demo.attandentSystem(inFilePath, outFilePath);
assertTrue(result);
assertTrue(isSame(outFilePath, targetPath));
} catch (Exception e) {
assertTrue(false);
}
}




public void testcaseSortDate_Case_01() {
testcaseHelper_Should_Success(TEST_FOLDER_PATH + "in.txt", TEST_FOLDER_PATH + "out.txt", TEST_FOLDER_TARGET + "check.txt");
}




}
wqj1993 2014-12-28
  • 打赏
  • 举报
回复

package huawei;


public final class Demo {

/**
* 考勤系统:统计考勤时间
* @param inFilePath 
* @param outFilePath
* @return 正常返回true,异常返回false
*/
public boolean attandentSystem(String inFilePath, String outFilePath)
{
return true;
}


}
wqj1993 2014-12-28
  • 打赏
  • 举报
回复

package huawei;


public final class Demo {

/**
* 考勤系统:统计考勤时间
* @param inFilePath 
* @param outFilePath
* @return 正常返回true,异常返回false
*/
public boolean attandentSystem(String inFilePath, String outFilePath)
{
return true;
}


}
guest6379 2014-12-28
  • 打赏
  • 举报
回复
代码用格式专用格式贴吧,


public class Hello{
static{
System.out.println("hello");
}
}



你是要分享你做的工程吗?
wqj1993 2014-12-28
  • 打赏
  • 举报
回复
这题有大神用2个小时做出来了,我用了10+个小时。。。 我的做法: 读取数据到Vector,然后转化成数组进行处理,最后输出。 有人想看的话我把原工程和我做好的工程发给你。
wqj1993 2014-12-28
  • 打赏
  • 举报
回复
测试用例的代码: package testcase; import huawei.Demo; import junit.framework.TestCase; import java.io.*; import java.util.Vector; public class DemoTest extends TestCase { private Demo demo; private final static String USER_DIR = System.getProperty("user.dir"); private final static String TEST_FOLDER_PATH = USER_DIR + "\\testCase\\"; private final static String TEST_FOLDER_TARGET = TEST_FOLDER_PATH + "target\\"; public void setUp() { demo = new Demo(); } private Vector<String> readOutputFile(String filePath) { Vector<String> vector = new Vector<String>(); try { FileInputStream fs = new FileInputStream(filePath); InputStreamReader isr = new InputStreamReader(fs); BufferedReader br = new BufferedReader(isr); String data = ""; while ((data = br.readLine()) != null) { if (data.length() == 0) { continue; } vector.add(data); } } catch (FileNotFoundException e) { throw new RuntimeException("文件路径错误!"); } catch (IOException e) { throw new RuntimeException("文件读取失败!"); } return vector; } private boolean isSame(String output, String targetPath) { Vector<String> vector = this.readOutputFile(output); Vector<String> tgVector = this.readOutputFile(targetPath); if (vector.size() != tgVector.size()) { return false; } for (int i = 0; i < vector.size(); i++) { if (!vector.get(i).equals(tgVector.get(i))) { return false; } } return true; } private void testcaseHelper_Should_Fail(String inFilePath, String outFilePath) { try { boolean result = demo.attandentSystem(inFilePath, outFilePath); assertFalse(result); } catch (Exception e) { assertTrue(true); } } private void testcaseHelper_Should_Success(String inFilePath, String outFilePath, String targetPath) { try { boolean result = demo.attandentSystem(inFilePath, outFilePath); assertTrue(result); assertTrue(isSame(outFilePath, targetPath)); } catch (Exception e) { assertTrue(false); } } public void testcaseSortDate_Case_01() { testcaseHelper_Should_Success(TEST_FOLDER_PATH + "in.txt", TEST_FOLDER_PATH + "out.txt", TEST_FOLDER_TARGET + "check.txt"); } }
wqj1993 2014-12-28
  • 打赏
  • 举报
回复
代码如下: package huawei; public final class Demo { /** * 考勤系统:统计考勤时间 * @param inFilePath * @param outFilePath * @return 正常返回true,异常返回false */ public boolean attandentSystem(String inFilePath, String outFilePath) { return true; } }

50,526

社区成员

发帖
与我相关
我的任务
社区描述
Java相关技术讨论
javaspring bootspring cloud 技术论坛(原bbs)
社区管理员
  • Java相关社区
  • 小虚竹
  • 谙忆
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧