Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Learn Challenge: Validating Member Information | Strings
Introduction to Java
Section 4. Chapter 8
single

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.

  1. Create 3 variables with the following exact values:
    • memberName ("Emily")
    • memberEmail ("espresso.lover@coffeeclub.com")
    • membershipId ("VIP-2026-XL")
  2. Compare strings: check whether the membership ID is equal to "VIP-2026-XL" — use proper string comparison (equals()), not ==.
  3. Validate strings: create one boolean variable named isValid that 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"
  4. Extract information from the email: extract only the username part (everything before the "@" symbol).
  5. Build a membership message using concatenation: "Member <username> has active membership <membershipId>"
  6. 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

Switch to desktopSwitch to desktop for real-world practiceContinue from where you are using one of the options below
Everything was clear?

How can we improve it?

Thanks for your feedback!

Section 4. Chapter 8
single

single

Ask AI

expand

Ask AI

ChatGPT

Ask anything or try one of the suggested questions to begin our chat

some-alt