Section 4. Chapter 8
single
Challenge: Validating Member Information
Swipe to show menu
Task
Swipe to start coding
You'll simulate how a coffee shop system processes membership information before allowing a customer to access special member benefits. The system needs to compare text values, validate customer information, and extract useful data from strings like usernames and membership IDs.
- Create 3 variables with the following exact values:
memberName("Emily")memberEmail("espresso.lover@coffeeclub.com")membershipId("VIP-2026-XL")
- Compare strings: check whether the membership ID is equal to
"VIP-2026-XL"— use proper string comparison (equals()), not==. - Validate strings: create one
booleanvariable namedisValidthat checks all of the following conditions:- the member name is not empty
- AND the email ends with
".com" - AND the membership ID starts with
"VIP"
- Extract information from the email: extract only the username part (everything before the
"@"symbol). - Build a membership message using concatenation:
"Member <username> has active membership <membershipId>" - Print all results. Output should be as follows:
Membership matches: true
Valid membership data: true
Username: espresso.lover
Membership message: Member espresso.lover has active membership VIP-2026-XL
Solution
Everything was clear?
Thanks for your feedback!
Section 4. Chapter 8
single
Ask AI
Ask AI
Ask anything or try one of the suggested questions to begin our chat