Buggy code:
public class SectorState extends State { private KeyboardListener keyboard ; private SpaceBackgroundFx bg ; int currentOption = 0 ; private Player player ; private Ship ship ; private Sector sector ; private Grid grid ; private AudioClip laser ; private AudioClip explosion ; private AudioClip bgmusic ; public SectorState ( StateManager manager ) { } public ShipData createShip ( ) { } @ Override public void initialize ( ) { } @ Override public void update ( ) { bg . update ( keyboard , ship . getSpeed ( ) ) ; for ( int i = 0 ; i < 12 ; i ++ ) { for ( int j = 0 ; j < 12 ; j ++ ) { grid . getSector ( j , i ) . update ( ) ; for ( int k = 0 ; k < ( grid . getSector ( j , i ) . getEntities ( ) . size ( ) ) ; k ++ ) { if ( ( ( grid . getSector ( j , i ) . getEntities ( ) . get ( k ) ) instanceof EnemyShip ) && ( ( ( ( EnemyShip ) ( grid . getSector ( j , i ) . getEntities ( ) . get ( k ) ) ) . getFleet ( ) . getShips ( ) . size ( ) ) == 0 ) ) { grid . getSector ( j , i ) . getEntities ( ) . remove ( k ) ; } } } } sector = grid . getSector ( ship . getSecX ( ) , ship . getSecY ( ) ) ; sector . setKnown ( true ) ; for ( int i = 0 ; i < ( sector . getEntities ( ) . size ( ) ) ; i ++ ) { if ( ( sector . getEntities ( ) . get ( i ) ) instanceof EnemyShip ) { EnemyShip e = ( ( EnemyShip ) ( sector . getEntities ( ) . get ( i ) ) ) ; double distance = Math . sqrt ( ( ( Math . pow ( ( ( ship . getX ( ) ) - ( e . getX ( ) ) ) , 2 ) ) + ( Math . pow ( ( ( ship . getY ( ) ) - ( e . getY ( ) ) ) , 2 ) ) ) ) ; <START_BUG> if ( distance < 400 ) { <END_BUG> double xDis = ( ship . getX ( ) ) - ( e . getX ( ) ) ; double yDis = ( ship . getY ( ) ) - ( e . getY ( ) ) ; double neg = 180 ; if ( ( ship . getX ( ) ) >= ( e . getX ( ) ) ) { neg = 0 ; } e . setRot ( ( ( ( ( Math . atan ( ( yDis // xDis ) ) ) * 180 ) // ( Math . PI ) ) + neg ) ) ; } } } if ( ! ( ship . isDestroyed ( ) ) ) { this . shipCollisions ( ) ; if ( ( ship . getDurability ( ) ) <= 0 ) { sector . getEntities ( ) . add ( new com . starshipsim . entities . Explosion ( ( ( ship . getX ( ) ) - 300 ) , ( ( ship . getY ( ) ) - 300 ) , ( ( ship . getWidth ( ) ) + 600 ) , ( ( ship . getHeight ( ) ) + 600 ) ) ) ; } } this . bulletCollisions ( ) ; this . enemyShipColisions ( ) ; if ( ! ( sector . isKnown ( ) ) ) { sector . setKnown ( true ) ; } if ( ( keyboard . keyDownOnce ( KeyEvent . VK_Q ) ) && ( ! ( ship . isDestroyed ( ) ) ) ) { manager . addState ( new MapState ( manager ) ) ; } if ( keyboard . keyDownOnce ( KeyEvent . VK_ESCAPE ) ) { bgmusic . stop ( ) ; manager . popState ( ) ; } if ( ( keyboard . keyDownOnce ( KeyEvent . VK_SPACE ) ) && ( ! ( ship . isDestroyed ( ) ) ) ) { sector . getEntities ( ) . add ( ship . shootBullet ( ) ) ; laser . play ( ) ; } ship . update ( ) ; ship . move ( this . getCanvas ( ) ) ; addEnemyShip ( ) ; } public void bulletCollisions ( ) { } public void enemyShipColisions ( ) { } public void shipCollisions ( ) { } @ Override public void draw ( Graphics g ) { } @ Override public void end ( ) { } public boolean checkForEnemySectors ( ) { } public void addEnemyShip ( ) { } public void moveSpace ( ) { } public AudioClip getBgmusic ( ) { } public void setBgmusic ( AudioClip bgmusic ) { } }

Fix:
if ( ( distance < 400 ) && ( ! ( ship . isDestroyed ( ) ) ) ) {