Kasmile的专栏

Studies this matter, lacks the time, but is lacks diligently.

懒助教作业/考勤登记

在这学期当软院的计算机网络助教时,发觉作业统计、考勤汇总以及实验成绩登记时都是个极大的工程,一是学生人数多,二是一周两次课均需要考勤,工作量算比较大。如果单纯的手工操作,不仅误差大,且相当繁琐。遂,和阿福哥一起搞了个 小程序用来做为作业考勤登记,其实也只是java上简单的io操作,利用poi-3.0.2-FINAL-20080204.jar包与xls文档进行直接读写交互。命令行,加之小键盘使得从统计工作相当之快以及方便。程序撰写得比较杂乱,用java确不面向对象,倒是面向过程。有需求,就有实现,随意了,可用实用即可了。:)

~65]4_LGF9YT@}51{YX]AHM

ATG4~@J0LE`_H8}8R~NKK[K

当过助教的同学,应该均需对一大堆作业进行登记分数/或者对提交的情况统计,更甚者要对学生每次的考勤进行汇总,用xls文档统计。这时难免需要,从纸上到电脑上的一个转移过程。一个小小程序,会带来诸多方便。经过一学期的使用,自己获益良多,遂共享之。(程序的所有相关放到我的资源共享里。)

程序功能:(1)作业登记。 一个系别的学生必然学号的大部分是一样的,输入的时候便只要不同部分即可。再输入成绩,则一份作业便登记完成。一个助教报学号,成绩,另个负责输入,流水线的操作可使得时间大大缩减。

   (2)考勤登记。即只有输入学号即可,把输入成绩这个步骤省略点(如,让成绩默认为A即可)。

   (3) log日志文件。当登记时,有时难免会输入错误,会出现登记两次的情况下。程序给出日志文档,并提示之前的一次登记是出现在第几份作业里,很方便你查找出错误,并矫正。

对有需要的同学,或许可以尝试 使用下,若有使用问题或有其他功能需求的同学,可联系本人。专业人士,莫见笑。:)

  1:  import java.text.SimpleDateFormat;
  2:  import java.util.*;
  3:  import java.io.*;
  4:  import org.apache.poi.poifs.filesystem.*;
  5:  import org.apache.poi.hssf.usermodel.*;
  6:   
  7:  public class RecordMark {
  8:   
  9:      public String getNowTime() {
 10:          String now = new SimpleDateFormat("yyyy_MM_dd_HH_mm_ss")
 11:                  .format(Calendar.getInstance().getTime());
 12:          return now;
 13:      }
 14:   
 15:      public void printSelect() {
 16:          System.out.println("==================================");
 17:          System.out.println("(1) 登记作业模式");
 18:          System.out.println("(2) 点名模式/实验模式");
 19:          System.out.println("(3) 查看或编辑xls文档");
 20:          System.out.println("(0) 退出");
 21:          System.out.println("==================================");
 22:          System.out.print("请选择(0~3): ");
 23:      }
 24:   
 25:      public void SelectFunc() {
 26:          while (true) {
 27:              printSelect();
 28:              InputStreamReader in = new InputStreamReader(System.in);
 29:              try {
 30:                  int temp = in.read() - 48;
 31:                  if (temp > 4 || temp < 0)
 32:                      continue;
 33:                  if (temp == 3) {
 34:                      Runtime.getRuntime().exec("cmd.exe /c " + editFile);
 35:                      continue;
 36:                  } else {
 37:                      mode = temp + "";
 38:                      break;
 39:                  }
 40:              } catch (Exception e) {
 41:                  e.printStackTrace();
 42:              }
 43:          }
 44:      }
 45:   
 46:      public void writeADataIntoExcel() {
 47:          try {
 48:              String filename = editFile;
 49:              String prevStuNum = preNum;
 50:              int numlength = Integer.parseInt(numLength);
 51:              String cord = record;
 52:              recordNum = 0;
 53:   
 54:              while (true) {
 55:                  String filename1 = "log/" + getNowTime().substring(0, 13) + ".txt";
 56:                  FileWriter foutwriter = new FileWriter(filename1, true);
 57:                  FileInputStream finput = new FileInputStream(filename);
 58:                  // 以巢状回圈读取所有储存格资料
 59:                  POIFSFileSystem fs = new POIFSFileSystem(finput);
 60:                  HSSFWorkbook wb = new HSSFWorkbook(fs);
 61:                  HSSFSheet sheet = wb.getSheetAt(0);
 62:                  HSSFRow row = null;
 63:                  HSSFCell cell = null;
 64:                  short i = 0;
 65:                  short y = 0;
 66:   
 67:                  Vector studentNumVector = new Vector();
 68:                  Vector havedNumVector = new Vector();
 69:   
 70:                  int col = 0;
 71:                  int numm = 0;
 72:                  BufferedReader br = new BufferedReader(new InputStreamReader(
 73:                          System.in));
 74:                  while (true) {
 75:                      System.out.print("输入要记录的作业次数(1~n)(0退出):");
 76:                      String str = br.readLine();
 77:                      int flag = 0;
 78:                      try {
 79:                          if (str != null && !str.equals("")) {
 80:                              numm = Integer.parseInt(str);
 81:                          } else {
 82:                              flag = 1;
 83:                          }
 84:                          if (numm < col) {
 85:                              flag = 1;
 86:                          }
 87:                      } catch (Exception e2) {
 88:                          System.out.println(e2);
 89:                          flag = 1;
 90:                      }
 91:                      if (flag == 1) {
 92:                          System.out.print("输入有误!/n");
 93:   
 94:                      } else {
 95:                          break;
 96:                      }
 97:                  }
 98:                  if (numm == 0) {
 99:                      break;
100:                  }
101:                  col = numm + 1;
102:                  foutwriter.write("******************************/r/n");
103:                  foutwriter.write(getNowTime() + "||" + " 准备开始记录:" + "第" + numm
104:                          + "次" + "/r/n");
105:                  System.out.println("********************/n准备开始记录:" + "第" + numm
106:                          + "次");
107:                  for (i = 1; i <= sheet.getLastRowNum(); i++) {
108:                      row = sheet.getRow(i);
109:                      y = (short) 0;
110:                      cell = row.getCell(y);
111:                      switch (cell.getCellType()) {
112:                      case HSSFCell.CELL_TYPE_NUMERIC:
113:                          int num1 = (int) cell.getNumericCellValue();
114:                          String numstr = num1 + "";
115:                          studentNumVector.add(numstr.substring(0, 14));
116:                          break;
117:                      case HSSFCell.CELL_TYPE_STRING:
118:                          studentNumVector.add(cell.getStringCellValue()
119:                                  .substring(0, 14));
120:                          break;
121:                      case HSSFCell.CELL_TYPE_FORMULA:
122:                          // System.out.print( cell.getNumericCellValue()+"31");
123:                          // 读出公式储存格计算后的值
124:                          // 若要读出公式内容,可用cell.getCellFormula()
125:                          break;
126:                      default:
127:                          // out.print("不明的格式");
128:                          System.out.print("");
129:                          break;
130:                      }
131:                  }
132:                  String stuno = "";
133:                  int exit = 0;
134:                  try {
135:                      while (true) {
136:                          String str;
137:                          String namesstr = "";
138:                          while (true) {
139:                              System.out.print("/n***********/n输入学号(0退出):");
140:                              str = br.readLine();
141:                              int flag = 0;
142:                              try {
143:                                  if (str != null && !str.equals("")) {
144:                                      if (str.length() == 1
145:                                              && str.toCharArray()[0] == '0') {
146:                                          exit = 1;
147:                                          break;
148:                                      }
149:                                      stuno = prevStuNum + str;
150:                                      if (str.length() == numlength) {
151:                                          stuno = str;
152:                                      }
153:                                  } else {
154:                                      flag = 1;
155:                                  }
156:                                  System.out.println(stuno);
157:                                  if (flag != 1 && stuno.length() == numlength
158:                                          && studentNumVector.contains(stuno)) {
159:                                      int rrow = studentNumVector.indexOf(stuno) + 1;
160:                                      row = sheet.getRow(rrow);
161:                                      cell = row.getCell((short) 1);
162:                                      namesstr = cell.getStringCellValue();
163:                                      System.out.println(stuno + "==>>姓名:"
164:                                              + cell.getStringCellValue());
165:   
166:                                  } else {
167:                                      flag = 1;
168:                                  }
169:   
170:                              } catch (Exception e2) {
171:                                  flag = 1;
172:                              }
173:                              if (flag == 1) {
174:                                  System.out.print("输入学号无效!请重新输入!/n");
175:                              } else {
176:                                  break;
177:                              }
178:                          }
179:                          if (exit == 1) {
180:                              break;
181:                          }
182:                          int wrongNum = 0;
183:   
184:                          if (mode.equals("1")) {
185:                              // 普通登记作业成绩模式
186:                              while (true) {
187:                                  System.out.print("输入成绩(ABCD):");
188:                                  str = br.readLine();
189:                                  int flag = 0;
190:                                  if (str.length() == 1) {
191:                                      int cordint = Integer.parseInt(str);
192:                                      if (cordint == 0) {
193:                                          wrongNum++;
194:                                          break;
195:                                      }
196:                                      if (cordint > 0 && cordint < 5) {
197:                                          char c = (char) ('A' + cordint - 1);
198:                                          str = "" + c;
199:                                          break;
200:                                      }
201:                                      str = str.toUpperCase();
202:                                      if (str.toCharArray()[0] >= 'A'
203:                                              && str.toCharArray()[0] <= 'D') {
204:                                          break;
205:                                      } else {
206:                                          flag = 1;
207:                                      }
208:                                  } else {
209:                                      flag = 1;
210:                                  }
211:                                  if (flag == 1) {
212:                                      System.out.print("输入成绩无效!请重新输入!/n");
213:                                  }
214:                              }
215:                          } else if (mode.equals("2")) {
216:                              // 登记实验成绩模式//点名模式
217:                              str = cord;
218:                          }
219:                          if (wrongNum != 0)
220:                              continue;
221:                          if (studentNumVector.contains(stuno)) {
222:                              int rrow = studentNumVector.indexOf(stuno) + 1;
223:                              row = sheet.getRow(rrow);
224:   
225:                              if (row.getCell((short) col) != null
226:                                      && !row.getCell((short) col)
227:                                              .getStringCellValue().isEmpty()) {
228:                                  int repeatNum = 0;
229:                                  if(havedNumVector.contains(stuno)){
230:                                      repeatNum = havedNumVector.indexOf(stuno) + 1;
231:                                  }
232:                                  String oldRecord = row.getCell((short) col)
233:                                          .getStringCellValue();
234:                                  System.out.println("学号:"
235:                                          + stuno
236:                                          + "   姓名:"
237:                                          + namesstr
238:                                          + "   已经记录成绩为:"
239:                                          + row.getCell((short) col)
240:                                                  .getStringCellValue());
241:                                  System.out.println("已记录在第 " + repeatNum + " 份, 倒数第 " + (recordNum - repeatNum + 1) + " 份");
242:                                  System.out.println("是否修改成绩为: " + str + "/n"
243:                                          + "Yes: 1 === No: 0  || 请输入 1 or 0:");
244:                                  while (true) {
245:                                      String s = br.readLine();
246:                                      if (s != null & !s.isEmpty()) {
247:                                          if (s.toCharArray()[0] == '1') {
248:                                              row.createCell((short) col)
249:                                                      .setCellValue(str);
250:                                              System.out.print("学号:" + stuno
251:                                                      + "   姓名:" + namesstr
252:                                                      + "   成绩由: " + oldRecord
253:                                                      + " 修改为:" + str + "/n");
254:                                              //recordNum++;
255:                                              foutwriter.write(getNowTime()
256:                                                      + "||" + " 学号:" + stuno
257:                                                      + "   姓名:" + namesstr
258:                                                      + "   成绩由: " + oldRecord
259:                                                      + " 修改为:" + str + "/r/n");
260:                                              break;
261:                                          } else if (s.toCharArray()[0] == '0') {
262:                                              System.out.print("学号:" + stuno
263:                                                      + "   姓名:" + namesstr
264:                                                      + "   成绩未修改,仍是:"
265:                                                      + oldRecord + "/n");
266:                                              break;
267:                                          }
268:                                      }
269:                                  }
270:                              } else {
271:                                  havedNumVector.add(stuno);
272:                                  row.createCell((short) col).setCellValue(str);
273:                                  System.out.print("学号:" + stuno + "   姓名:"
274:                                          + namesstr + ":输入成功!   成绩是:" + str
275:                                          + "/n");
276:                                  foutwriter.write(getNowTime() + "||" + " 学号:"
277:                                          + stuno + "   姓名:" + namesstr
278:                                          + ":输入成功!   成绩是:" + str + "/r/n");
279:                                  recordNum++;
280:                              }
281:                          } else {
282:                              System.out.print("输入失败:查无此学号!/n");
283:                              foutwriter.write("输入失败:查无此学号!/r/n");
284:                          }
285:                      }        
286:                  } catch (IOException e) {
287:                      System.out.println("error");
288:                  }
289:                  FileOutputStream fileOut = new FileOutputStream(filename);
290:                  wb.write(fileOut);
291:                  fileOut.close();
292:                  foutwriter.write(getNowTime() + "||" + " :) 本次记录结束啦!总共记录:"
293:                          + recordNum + "/r/n");
294:                  foutwriter.write("******************************/r/n");
295:                  foutwriter.close();
296:              }
297:          } catch (Exception e) {
298:              System.out.println(e);
299:          }
300:      }
301:   
302:      /*
303:       * 读配置文件
304:       */
305:      public void readSetupIni() {
306:          try {
307:              FileReader fr = new FileReader("Setup.ini");// 创建FileReader对象,用来读取字符流
308:              BufferedReader br = new BufferedReader(fr); // 缓冲指定文件的输入
309:              String myreadline; // 定义一个String类型的变量,用来每次读取一行
310:              while (br.ready()) {
311:                  myreadline = br.readLine();// 读取一行
312:                  System.out.println(myreadline);// 在屏幕上输出
313:                  myreadline = br.readLine();// 读取一行
314:                  System.out.println(myreadline);// 在屏幕上输出
315:                  if (editFile == null) {
316:                      editFile = myreadline;
317:                      continue;
318:                  }
319:                  if (preNum == null) {
320:                      preNum = myreadline;
321:                      continue;
322:                  }
323:                  if (numLength == null) {
324:                      numLength = myreadline;
325:                      continue;
326:                  }
327:                  if (mode == null) {
328:                      mode = myreadline;
329:                      continue;
330:                  }
331:                  record = myreadline;
332:              }
333:              br.close();
334:              fr.close();
335:          } catch (IOException e) {
336:              System.out.println("新建配置文件,NewFile: Setup.ini.........");
337:              try {
338:                  FileWriter fw = new FileWriter("Setup.ini");// 创建FileWriter对象,用来写入字符流
339:                  BufferedWriter bw = new BufferedWriter(fw); // 将缓冲对文件的输出
340:                  bw.write("[EditFile]"); // 写入文件
341:                  bw.newLine();
342:                  bw.newLine();
343:                  bw.write("[preNum]"); // 写入文件
344:                  bw.newLine();
345:                  bw.newLine();
346:                  bw.write("[NumLength]"); // 写入文件
347:                  bw.newLine();
348:                  bw.newLine();
349:                  bw.write("[Mode]"); // 写入文件
350:                  bw.newLine();
351:                  bw.newLine();
352:                  bw.write("[Record]"); // 写入文件
353:                  bw.newLine();
354:                  bw.newLine();
355:                  bw.close();
356:                  fw.close();
357:              } catch (IOException e2) {
358:                  e2.printStackTrace();
359:              }
360:              e.printStackTrace();
361:          }
362:   
363:      }
364:   
365:      public String getMode() {
366:          return mode;
367:      }
368:   
369:      public boolean getRunFlag() {
370:          return runflag;
371:      }
372:   
373:      public static void main(String[] args) {
374:          RecordMark test = new RecordMark();
375:          while (test.runflag == true) {
376:              test.readSetupIni();
377:              test.SelectFunc();
378:              if (test.getMode().equals("0"))
379:                  return;
380:              test.writeADataIntoExcel();
381:          }
382:      }
383:   
384:      private boolean runflag = true;
385:      private String mode;
386:      private String editFile;
387:      private String preNum;
388:      private String numLength;
389:      private String record;
390:      private int recordNum;
391:  }
392:   
 1:  /****************************/           
 2:  /* 懒助教作业/考勤登记小程序
 3:  /* kasmile    
 4:  /* 2010-5-26
 5:  /****************************
 6:  
 7:  1. 需要安装配置好jvm.
 8:  2. 配置好Setup.ini 文件
 9:  [EditFile] //待编辑的xls文档
10:  a.xls
11:  [preNum] //学号一致的部分
12:  4092007810
13:  [numLength]//学号的总长度
14:  14
15:  [Mode] //选择模式
16:  1
17:  [Record] //模式2下的默认成绩
18:  A
19:  3. 直接点击RecordRun.bat即可
20:  4. 其中成绩登记分为A/B/C/D四个等级,可以1/2/3/4代替之输入即可
21:  5. 学号输入:把学号共同部分填入preNum,则命令只输不同部分即可。(当然全输入,也可以)
22:  6. log文件夹里存放登记的日志文件,xls文档格式需要如a.xls。
23:  7. 有问题blog.csdn.net/kasmile上留言 :)
阅读更多
个人分类: C/C++
想对作者说点什么? 我来说一句

助教 作业/考勤登记

2010年05月26日 878KB 下载

jsp+servlet考勤管理系统

2016年05月26日 17.19MB 下载

考勤管理系统的源代码

2012年08月25日 56KB 下载

中控iface人脸考勤源码

2013年05月30日 815KB 下载

Java+MySQL高校学生考勤系统

2018年02月07日 6.51MB 下载

基于jsp考勤管理系统

2015年03月25日 1.53MB 下载

command.awk

2016年10月02日 988B 下载

没有更多推荐了,返回首页

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭