修改点名源代码

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 wl121  
        if(args.length != 2){  
           System.out.println("参数输入不对");  
           System.out.println("使用方法(示例):java RegisterApp 名单文件名称  班级名称");  
           System.exit(0);  
       }  
          
        //(b)学生签到结果:学生到,输入1;缺课,输入0  
       System.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, 是否缺课标记flag  
        String strAbsent = "";  
       int nAbsent = 0;  
        int flag = 0;  
          
       while(input.hasNext()){  //循环读取学生数据 

           String strName = input.nextLine();
           if(strName.equals("27	魏凯毅"))
           {
                continue;  
                           } //修改代码
           //if(input.nextLine()=="")continue;
            //把学生名字输出到屏幕,从而进行点名。    
           //老师根据学生到课情况,输入1-到课,0-缺课,保存到flag中  
            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
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值