Welcome to the Codename Generator project! This project teaches programming concepts through creating fun secret agent codenames. Students will learn about Ruby programming by building three different versions of a codename generator, each one introducing new concepts.
By completing this project, students will understand:
- How to use Ruby classes and methods
- Working with arrays (lists of items)
- Random selection from arrays
- Using string length and character properties
- Basic algorithms for generating consistent output
Files: adjectives.rb
and nouns.rb
These files contain our word banks - collections of "tough" adjectives and nouns that make cool codenames.
Key Concepts:
- Classes: Think of a class like a container that holds related information
- Arrays: Lists of words stored between square brackets
[]
- Class Methods: Special functions that let us access the word lists
Example: When we call Adjectives.tough_adjectives
, we get back a list of words like "Savage", "Brutal", "Vicious", etc.
File: random_codename_generator.rb
What It Does: Picks a completely random adjective and noun to create a codename.
Key Concepts Introduced:
require_relative
: Importing code from other files.sample()
: Randomly selecting items from an array- String interpolation: Combining variables with text using
#{}
How It Works:
- Loads the word lists from our adjective and noun files
- Randomly picks one adjective
- Randomly picks one noun
- Combines them into a codename like "Savage Wolf"
Discussion Point: Every time you run this, you get a different codename. It's totally random!
File: simple_codename_generator.rb
What It Does: Creates a codename based on the length of your name.
Key Concepts Introduced:
- User input with
gets.chomp
- String properties:
.size
to count letters - Array indexing: Accessing specific positions in a list
- Variables to store user information
How It Works:
- Asks for your first and last name
- Counts the letters in each name
- Uses the letter count to pick a specific adjective (based on first name length)
- Uses the letter count to pick a specific noun (based on last name length)
- Combines them into your personalized codename
Discussion Point: If your name is "Jane Doe" (4 and 3 letters), you'll always get the same codename. Your friend with the same name length will get the same one too!
File: unique_codename_generator.rb
What It Does: Creates a unique codename that will always be the same for your specific name, but different from others.
Key Concepts Introduced:
- String manipulation:
.downcase
to make lowercase - Character encoding:
.ord
converts letters to numbers - Mathematical operations:
.sum
and modulo%
- Hash functions (simplified): Converting text into numbers
How It Works:
- Asks for your first and last name
- Combines and converts your full name to lowercase
- Converts each letter to a number and adds them up
- Uses modulo (remainder division) to pick from our word lists
- Creates a consistent, unique codename
Discussion Point: "Jane Doe" and "John Doe" will get different codenames even though their names have similar lengths. The actual letters matter!
- Introduce the concept of codenames and why they're cool
- Show the word lists (adjectives.rb and nouns.rb)
- Build and run the random generator together
- Have students modify the word lists to add their own words
- Review arrays and indexing
- Introduce user input concepts
- Build the simple generator
- Have students test with different names
- Discuss why some names give the same codename
- Discuss the problem: How do we make unique codenames?
- Introduce the concept of converting text to numbers
- Build the unique generator
- Compare results between all three generators
- Discuss real-world applications (usernames, passwords, etc.)
- Add More Word Lists: Create categories like colors, animals, or weather
- Three-Word Codenames: Add a third word category (like actions or locations)
- Codename Decoder: Write a program that can tell if two names would generate the same codename
- Visual Output: Add ASCII art or formatting to make the output more exciting
- Class: A blueprint for organizing code and data
- Array: An ordered list of items
- Method: A function that performs a specific task
- String: Text data in programming
- Variable: A container that stores information
- Algorithm: A step-by-step process to solve a problem
- Modulo (%): Gives the remainder after division
- Can students explain the difference between the three generators?
- Can they predict what codename a specific name will generate in the simple version?
- Can they add a new feature to one of the generators?
- Can they debug intentional errors introduced to the code?
This project uses fun, empowering words for codenames. If students want to add their own words, ensure they're appropriate for the classroom setting.