+ 1

Password Validator program in Java, all conditions are not fulfilling in coach (getting error in 4 out of 13 cases). Pls assist.

Below is link to question amd my program. The program is running fine for my test cases but not able to find error/solve 4 test cases. Question/Coach link: https://www.sololearn.com/coach/76?ref=app My program Link: https://code.sololearn.com/c7goNGrQ5WFb/?ref=app Task: Write a program that takes in a string as input and evaluates it as a valid password. The password is valid if it has at a minimum 2 numbers, 2 of the following special characters ('!', '@', '#', '

#x27;, '%', '&', '*'), and a length of at least 7 characters. If the password passes the check, output 'Strong', else output 'Weak'. Input Format: A string representing the password to evaluate. Output Format: A string that says 'Strong' if the input meets the requirements, or 'Weak', if not. Sample Input: Hello@$World19 Sample Output: Strong

12th May 2020, 10:24 PM
Kapil
Kapil - avatar
6 Answers
+ 2
the simpler code is better. I believe the problem is either with your switch statement or your classes, though its not clear to me extactly which it is. try using if else instead of the switch. if that still doesn’t work, place your codes directly in main. here is my code that works for ref https://code.sololearn.com/cKy4yY05S2WE/?ref=app
13th May 2020, 3:55 PM
Elizabeth Kelly
Elizabeth Kelly - avatar
+ 1
Hi, there are a few different issues with your code. First the section at line 16 is unnecessary. There is nothing in the problem that says certain characters are excluded. Second, your counts are not considering that digits and special chars could be repeated. ex: ghy44!! the code coach challenge would consider that string Strong but your code would print Weak.
13th May 2020, 5:43 AM
Elizabeth Kelly
Elizabeth Kelly - avatar
+ 1
though to be fair, there are some applications in the real world that do not allow repeating characters in passwords. 😉
13th May 2020, 5:45 AM
Elizabeth Kelly
Elizabeth Kelly - avatar
+ 1
sorry Kapil I couldn’t determine the exact cause. It might be a code coach issue. when I ran your code with some minor changes the number of test case failures fluctated between 6 and 2 - even if I hadn’t made further changes.
14th May 2020, 2:57 PM
Elizabeth Kelly
Elizabeth Kelly - avatar
0
I have initially tried the simpler form (no line 16 and duplication of special characters & number were allowed), but the code still didn't work for last 4 conditions. I have again modified the code for reference. Link: https://code.sololearn.com/cDF2qqkuJ3X6/?ref=app
13th May 2020, 6:50 AM
Kapil
Kapil - avatar
0
Thanks Elizabeth Kelly . Appreciate your efforts. Your code did work for all cases. I'll continue to look for the issues in my code.
14th May 2020, 8:58 AM
Kapil
Kapil - avatar