Skip to content

Instantly share code, notes, and snippets.

@lislon
Last active November 25, 2019 20:03
Show Gist options
  • Save lislon/bbb794cf433853f58b369b2d3acb6fb9 to your computer and use it in GitHub Desktop.
Save lislon/bbb794cf433853f58b369b2d3acb6fb9 to your computer and use it in GitHub Desktop.
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