Job Submission class: 13 Soft Gold 2 class all students
Deadline for job submission: April 30, 2016 before 24:00 (no results submitted after the deadline)
1, a website management system, the user registration, the phone number is optional input, the input format is: Area code-Telephone number-extension number, in the middle with "-" separated. The following is the design on the JSP page and does not have any control over the input.
Suppose the system now needs to take out the middle phone number part, the code is as follows:
/** * * This method takes the middle part of the phone number according to user input * @param strphonenum phone number, such as: "0591-83279988-002" * @return Returns the number part, such as: "83279988" */public String getphonenumber (string strphonenum) { if (strphonenum==null) | | ". Equals (Strphonenum)) { return" "; } String[] Arrphone=strphonenum.split ("-"); return arrphone[1]; }
Use the techniques and methods you have learned to identify the problems in this approach, and analyze the cause of the problem, and give your solution. (Hint: there is more than one problem)
Requirements:
(1) Write the question
(2) Write down the reason why the problem arises
(3) Give the modified code
Answer:
(1) Write the question:
①: No limit on the length of the number that can be entered
②: Undefined whether the input is a number or a string
③: not verified as empty
(2) Write down the reason why the problem arises:
public string Getphonenumber (string strphonenum) { if (strphonenum==null) | | ". Equals (Strphonenum)) { return" "; }
(3) Give the modified code:
public string Getphonenumber (string strphonenum) {
if ((strphonenum==null) | | | "". Equals (Strphonenum)) {
if (strphonenum.lenth==8 &&!pattern.compile ("^\\d{8}$"). Matcher (Phonenumber.trim
()). Matches ())) {
Return "true";
}
}
else{
Return "false";
SYSTEM.OUT.PRINTLN ("The input number format is not correct!!! ");
}
String[] Arrphone=strphonenum.split ("-");
return arrphone[1];
}
2, write a paragraph for the integer array sorting code, explain your design ideas, and use the error-guessing method to give a possible error (at least 5), design the test case, and use JUnit to write unit tests to test. (assuming that the passed-in parameter has been determined to be an integer array)
Requirements:
(1) Write code, and conform to code specification (naming to specification, not directly written in the main method, need to have class comments, method comments, and appropriate line comments)
(2) Explain your design ideas
(3) Write a possible error (at least five kinds)
(4) Write JUnit unit tests to put the test data that was previously given in the possible error into the unit test for testing
Answer:
(1) Write code, and conform to code specification (naming to specification, not directly written in the main method, need to have class comments, method comments, and appropriate line comments)
Package cn.cai.ha;
public class Cai {
/**
*
* @author Cai Heron Jia
*/
public static int[] Maopao (int[] x) {
This loop compares the two numbers of the array, passing the first number to the second number if the first number is larger than the second.
for (int i = 0; i<x.length; i++) {
for (int j= i+1; j<x.length; J + +) {
if (X[i]>x[j]) {
int temp = X[i];
X[i] = X[j];
X[J] = temp;
}
}
}
for (int i:x) {
SYSTEM.OUT.PRINTLN (i + "");
}
return x;
}
public static void Main (string[] args) {
TODO auto-generated Method Stub
Int[] I={-1,0,1,4,5,6,78,9,4,2,4,11,45,-8};
SYSTEM.OUT.PRINTLN ("The result after sorting is:");
Maopao (i);
System.out.println ();
}
}
(2) Explain your design ideas:
Using the bubble sort, I and j are compared, if I is greater than J, then it is invariant, conversely, I will be adjusted to the front of J, and finally can be obtained from a large to a small sort.
(3) Write a possible error (at least five kinds)
1, each number of the array is composed of a number and negative
2, array numbers are all the same
3, array number 0 start
4, the array has a negative number
5, array no numbers
Minjiang College School of the next 2015-2016 years software testing course-Third blog assignment