IDFC, a leading Bank sector offers online shopping to their customers, To avail this offer, the customer will have to generate a security code, for the first time usage of his card to purchase online.
Hint to generate a security code is as follows :
1.Minimum of 8 Characters
2.Must contain atleast one uppercase, one lowercase and one special character.
- Only the special characters @,*,# are allowed.
The code fails to meet the criteria, will response with an error message as shown in the sample output.
Develop an application to implement this scenario.
Write a public class Main with the main method. Write the code to get the input, validate and print the output.
Sample Input 1:
Generate your Security Code
Ab12345@
Sample Output 1:
Security Code Generated Successfully
Sample Input 2:
Generate your Security Code
S1995p123
Sample Output 2:
Invalid Security Code, Try Again!
I was able to come up with a code which basically passes all the visible condition, but failing to test one. Not really sure where I am going wrong.
import java.util.*;
import java.util.regex.*;
class Main{
public static void main(String a[]){
Scanner sc = new Scanner(System.in);
System.out.println("Generate your Security Code");
String code = sc.next();
String regex = "[A-Za-z0-9@*#]{8}";
Pattern p = Pattern.compile(regex);
Matcher m = p.matcher(code);
boolean matchFound = m.find();
if(matchFound)
System.out.println("Security Code Generated Successfully");
else
System.out.println("Invalid Security Code, Try Again!");
}
}
Evaluation Result:
Proposed grade: 75 / 100
Result Description
Failed tests
Test 3: Invalid Password
Test 1: Valid Password
Summary of tests
*Note: All the test cases might not have same weightage
4 tests run/ 3 tests passed