1) What PS11 wants (movie trailer)
The file format (ActorsMovies)
● A line with an actor name + birth year
● Then several movie lines underneath it that start with a tab \t
PS11
So it’s like:
ActorName<TAB>BirthYear
Movie 1
Movie 2
ActorName<TAB>BirthYear
Movie 1
...
Birth year might be missing; then you print \N
PS11
The interactive loop
Your program repeatedly does this:
1. User types some string (maybe wrong / typo)
PS11
2. You print 10 closest actor names, each with:
○ name
○ birth year (or \N)
○ edit distance from the typed string
PS11
3. User types a number 0–9 to choose which one
PS11
4. Print all the movies for that chosen actor
PS11
5. Repeat until empty input (see sample session)
PS11
Also: must answer a query in “a few seconds” for full credit
PS11
2) What your ListMovies.java is doing
(play-by-play)
A) Data structures (what gets stored)
Actor
An Actor stores:
● name
● year
● movies list
ListMovies
So one Actor object is literally:
“This actor + their birth year + their movie list”
Match
A Match stores:
● a pointer to an Actor
● the distance score (smaller is better)
ListMovies
So a Match is:
“This actor scored distance D from what the user typed”
B) Step 1: Read the ActorsMovies file and build the Actor
list
This happens in loadActors().
How it detects actor vs movie lines
● If a line starts with \t, it’s a movie line → add to the current actor’s movie list
ListMovies
● Otherwise, it’s an actor line:
○ split on tab
○ first piece = name
○ second piece (if exists) = year, else \N
○ make new Actor and set it as current
ListMovies
Monkey version:
When we see a new actor line, we “start a new bucket.”
Every tabbed line after that gets thrown into that bucket until the next actor line
shows up.
C) Step 2: Ask the user for a string in a loop
Main loop prints:
● Enter string:
● reads line
● trims it
● empty line ends program
ListMovies
D) Step 3: Compute “closest matches” (top 10)
This is the heart of PS11.
New concept: Edit distance
Edit distance means:
“minimum number of single-character edits to transform A into B”
Edits:
● insert
● delete
● substitute (replace)
Your code computes it using a DP table dp[m+1][n+1]
ListMovies
Monkey version:
It’s like a grid where each cell answers:
“How hard is it to change the first i letters of query into the first j letters of the actor
name?”
How you keep only the best 10
You scan every actor:
● compute distance
● create Match(actor, dist)
● insert into a sorted list best
● keep list size capped at 10
ListMovies
insertMatch() inserts it in the right position so best stays sorted by distance, then chops
anything beyond 10
ListMovies
Monkey version:
You’re running a contest:
every actor tries out, but you only keep the top 10 scores.
E) Step 4: Print the 10 matches exactly like the sample
format
Your output loop prints:
(i) Name (Year) dist
ListMovies
Which matches the assignment example session (tim tayler → 10 matches → index choice)
PS11
F) Step 5: User chooses 0–9, then you print movies
● print Enter choice:
● parse integer
● validate bounds
● pick that actor
● print:
Actor X appeared in:
(movie lines...)
ListMovies
That matches the sample session format too
PS11
The “WHY” of PS11 (what it’s really
testing)
PS11 is testing 4 skills:
1. File parsing with a simple “structure marker” (tab indentation)
PS11
2. Storing records (actor → list of movies)
3. Edit distance as a DP algorithm
PS11
4. Top-10 selection (don’t sort everything, keep only best 10)
Monkey-brain summary block you can
paste in notes
PS11 (ListMovies) = “search actors by typo similarity”
1) Read ActorsMovies:
- non-tab line = new Actor (name + year)
- tab line = movie for current Actor
2) Loop:
- user types string
- compute editDistance(query, each actor name)
- keep the 10 smallest distances
- print (0..9) list: name (year) distance
- user picks a number
- print all movies for that actor