Last active
November 25, 2019 20:03
-
-
Save lislon/bbb794cf433853f58b369b2d3acb6fb9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Random; | |
public class SpaceRocketLaunch { | |
@FunctionalInterface | |
interface PrepareActions { | |
boolean prepare(); | |
} | |
public static void main(String[] args) { | |
PrepareActions launchPreparation = getLaunchPreparation(); | |
if (launchPreparation.prepare()) { | |
System.out.println("Запуск"); | |
} | |
} | |
private static PrepareActions getLaunchPreparation() { | |
var missionControl = getMissionControlPreparations(); | |
var crew = getCrewPreparations(); | |
return () -> { | |
if (missionControl.prepare() && crew.prepare()) { | |
System.out.println("Экипаж и центр управления готовы к запуску"); | |
return true; | |
} else { | |
System.out.println("Запуск невозможен"); | |
return false; | |
} | |
}; | |
} | |
private static PrepareActions getMissionControlPreparations() { | |
return () -> { | |
System.out.println("ЦЕНТР КОНТРОЛЯ: Проверяем все ли системы в норме"); | |
return true; // всегда в норме | |
}; | |
} | |
private static PrepareActions getCrewPreparations() { | |
return () -> { | |
System.out.println("ЭКИПАЖ: Проверяем все ли системы в норме"); | |
boolean isSpaceshipOk = new Random().nextBoolean(); | |
if (isSpaceshipOk) { | |
System.out.println("ЭКИПАЖ: Всё Ок. Ключ на старт"); | |
return true; | |
} else { | |
System.out.println("ЭКИПАЖ: У нас проблема"); | |
return false; | |
} | |
}; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment