Inheritance and Control Flow: Password Validation System
Problem Description
inheritance and Control Flow: Password Validation System
In this problem, you will create a program that implements a StrictValidator class inheriting from Validator, overrides the validate method to apply different password length criteria, and displays the validation result to standard output.
Learning Objective: Understand how to implement different validation rules with inheritance and method overriding
Create basic password validator class and strict validator class that inherits from it. Learn object-oriented flexibility by applying different validation criteria with same validate method depending on class.
Understanding with Concrete Examples
Example 1: Pass Strict Criteria (12 characters)
- Input:
12 - Class Used: StrictValidator (10+ character standard)
- Validation Processing:
12 >= 10→ true - Judgment Result: "Valid"
- Output: "Password Validation:" "Length: 12characters" "Result: Valid"
Example 2: Fail Strict Criteria (8 characters)
- Input:
8 - Class Used: StrictValidator (10+ character standard)
- Validation Processing:
8 >= 10→ false - Judgment Result: "Invalid" (Would pass with basic class but fails with strict class)
- Output: "Password Validation:" "Length: 8characters" "Result: Invalid"
Example 3: Boundary Value (exactly 10 characters)
- Input:
10 - Class Used: StrictValidator (10+ character standard)
- Validation Processing:
10 >= 10→ true (boundary value included) - Judgment Result: "Valid"
- Output: "Password Validation:" "Length: 10characters" "Result: Valid"
Input
Line 1: Password length (integer, 1-50)
Output
Password Validation:
Length: [length]characters
Result: [result]
Validation criteria:
- Basic Class (Validator): Pass with 6+ characters
- Strict Class (StrictValidator): Pass with 10+ characters (override)
Key Point: Using inheritance enables achieving different behavior with same method name. This is called polymorphism.
Test Cases
※ Output examples follow programming industry standards
12
Password Validation: Length: 12characters Result: Valid
8
Password Validation: Length: 8characters Result: Invalid
10
Password Validation: Length: 10characters Result: Valid
5
Password Validation: Length: 5characters Result: Invalid
Your Solution
You have 6 free executions remaining
