签到程序代码更改

来源:互联网 发布:java socket服务器 编辑:程序博客网 时间:2024/04/30 15:07

原代码:链接http://blog.csdn.net/dyz1982/article/details/20311823

修改之后的代码:

import java.io.File;import java.io.FileNotFoundException;import java.io.PrintWriter;import java.text.SimpleDateFormat;import java.util.Date;import java.util.Scanner;public class RegisterApp {/** * @param args * @throws Exception  */public static void main(String[] args) throws Exception {// TODO Auto-generated method stub//(a)使用命令行参数,输入学生名单,和 班级名称//    使用格式: java RegisterApp list.txt wl121if(args.length != 2){System.out.println("参数输入不对");System.out.println("使用方法(示例):java RegisterApp 名单文件名称  班级名称");System.exit(0);}//(b)学生签到结果:学生到,输入1;缺课,输入0System.out.println("——————————————————");System.out.println("简易学生签到程序V0.1");System.out.println("老师叫到名字,请答‘到’");System.out.println("1:到课       0:缺课");System.out.println("——————————————————");//(c)取得系统当前日期时间Date now = new Date(); SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMdd_HHMM");//可以方便地修改日期格式String strDate = dateFormat.format( now ); System.out.println("当前时间:"+strDate);  //(d)读取学生名单,args[0]为学生名单文件,args[1]为班级名称String fileList = args[0];String fileCheck = args[1] + strDate + ".txt";File fileInput = new File(fileList);File fileOutput = new File(fileCheck);//(e)利用Scanner类读取文本数据/键盘输入数据;  PrintWriter类把签到结果写入到文件Scanner input = new Scanner(fileInput);Scanner sc = new Scanner(System.in);PrintWriter output = new PrintWriter(fileOutput);//保存缺课学生名字strAbsent ,缺课学生人数nAbsent, 是否缺课标记flagString strAbsent = "";int nAbsent = 0;int flag = 0;while(input.hasNext()){  //循环读取学生数据String strName = input.nextLine();//把学生名字输出到屏幕,从而进行点名。  //老师根据学生到课情况,输入1-到课,0-缺课,保存到flag中if(strName.equals("29谢锐鹏")){flag = 1;}else{System.out.println(strName);flag = sc.nextInt();}//如果缺课,则记录下缺课学生数目 与 名字if(flag==0){nAbsent = nAbsent+1;strAbsent = strAbsent + " " + strName;}//把考勤结果写入名单output.print(strName);output.print("    ");output.println(flag);}//关闭I/O管道sc.close();output.close();input.close();System.out.println("——————————————————————————");System.out.println("考勤结束.");System.out.printf("一共有%d个同学缺课,分别是:%s\n",nAbsent,strAbsent);System.out.println("——————————————————————————");}}


0 0
原创粉丝点击