Ask your professor to clarify the requirement. You can make it get the output she wants exactly, but it is a lot of synchronizing work and may not be what she actually wants.
If it is what she wants then you have to:
- Determine which thread you are in
- Compare the current
word with the words that this thread should yield to the other thread.
- Use a synchronization token to notify the other thread
- Wait on the same synchronization token