1. Description of the problem
Enter the year to determine whether it is a leap years.
2. Judging conditions
1) A leap year that can be divisible by 4 and not divisible by 100.
2) A leap year that can be divisible by 100 and divisible by 400.
3. Equivalence class Partitioning
Number |
Valid equivalence classes |
Number |
Invalid equivalence class |
1 |
Can be divisible by 400. |
3 |
Can be divisible by 100 and not divisible by 4. |
|
2 |
Can be divisible by 4 and not divisible by 100. |
4 |
Not divisible by 4. |
5 |
Illegal input (including negative numbers) |
4. Test Cases
Number |
Input |
overriding equivalence classes |
Output |
1 |
1600 |
1 |
1600 is a leap year |
2 |
2012 |
2 |
2012 is a leap year |
3 |
1700 |
3 |
1700 Non-leap year |
4 |
2014 |
4 |
2014 non-leap year |
5 |
2015 |
4 |
2015 non-leap year |
6 |
. efe32 |
5 |
Please enter a valid year |
7 |
|
5 |
Please enter a valid year |
5. Code implementation
parseint () and isNaN () are used in the function of the JSP to determine the illegal input
1<%@ page language= "Java"Import= "java.util.*" pageencoding= "Utf-8"%>2<%@ page contenttype= "text/html; Charset=utf-8 "%>3<%@ pageImport= "Java.sql.*"%>4<%5String Path =Request.getcontextpath ();6String basepath = request.getscheme () + "://" +request.getservername () + ":" +request.getserverport () +path+ "/";7%>8 9<! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" >Ten One A<base href= "<%=basePath%>" > - -<title> Testing </title> the<meta http-equiv= "Pragma" content= "No-cache" > -<meta http-equiv= "Cache-control" content= "No-cache" > -<meta http-equiv= "Expires" content= "0" > -<meta http-equiv= "keywords" content= "keyword1,keyword2,keyword3" > +<meta http-equiv= "description" content= "This is my page" > - + A<script> at function judge () { -var text = document.getElementById (0). Value; - var i; -var str =NewArray ("is a leap year", "Non-leap years", "Please enter a valid vintage"); - -var year =parseint (text); in if(Year < 0 | |IsNaN (year)) { -i = 2; to}Else if(Year% 400 = = 0){ +i = 0; -}Else if(year% 100 = = 0){ thei = 1; *}Else if(year% 4 = = 0){ $i = 0;Panax Notoginseng}Elsei = 1; - thevar out = ""; + if(i = = 2){ AOut + =Str[i]; the}Else{ +Out + = text +Str[i]; - } $ alert (out); $ } - -</script> the -<body>WuyiThis is my JSP page. <br> the<center><tr style= "Text-align:center" > Test leap Year </tr><br><br> -<tr style= "Text-align:center" >Please enter the year: Wu<input type = "text" id= "0" ></tr><br><br> -<button type= "button" onclick= "Judge ();" align = "center" > OK </button></tr> About</center> $</body> -6. Test results
Number |
Input |
Output |
1 |
1600 |
|
2 |
2012 |
|
3 |
1700 |
|
4 |
2014 |
|
5 |
2015 |
|
6 |
. efe32 |
|
7 |
|
|
Illegal input issues for leap years