added pseudocode in a java style for phase 2 and phase 3