The engine in your car has Throttle by cable. It would be easiest to install a 2003 to 2004 engine from a Vibe, Matrix, or Corolla.
The 2005 and newer engines are Drive by wire (DBW). This engine would also work, but you would need to swap the Throttle Body from the broken engine on to the used engine.
The 2002 Corolla engine *should* be the same.
Do not consider a Vibe/Matrix AWD engine, or an engine from a GT / XRS, these engine are different.
Edited: To fix the years and naming per this other thread viewtopic.php?t=40003