软工作业PSP与单元测试训练

(一)任务说明

     实现模块判断传入的电子邮箱账号的正确性。

(二)实现要求

    (1)实现功能模块:通过正则表达式进行简单的判断。

        (2)针对实现模块编写对应单元测试代码:

 1 /*
 2  * To change this license header, choose License Headers in Project Properties.
 3  * To change this template file, choose Tools | Templates
 4  * and open the template in the editor.
 5  */
 6 package emailcheck;
 7 
 8 import java.util.Scanner;
 9 import java.util.regex.Pattern;
10 
11 /**
12  *
13  * @author EvanPatrick
14  */
15 public class EmailCheck {
16     public  static void main(String arg[]) {
17         Scanner str=new Scanner(System.in);
18         String email = str.nextLine(); 
19            while(true)
20           {
21           
22            if (EmailCheck.checkEmail(email))
23            {   
24                 System.out.println(email+"is legal Email address!");
25                 break;
26            }
27            else
28            {
29                 System.out.println(email+"is illegal Email address!");
30                 break;
31            }
32           }
33        } 
34      public static boolean checkEmail(String email) {     
35             String pattern= "\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*";  
36             return Pattern.matches(pattern, email);     
37         }       
38 }

测试结果:

        (3)按PSP流程进行工作量估算,填写任务清单工作量估算表。

原文地址:https://www.cnblogs.com/evanpatrick/p/8594003.html