Search in sources :

Example 1 with LotteryModule

use of com.iluwatar.hexagonal.module.LotteryModule in project java-design-patterns by iluwatar.

the class ConsoleAdministration method main.

/**
 * Program entry point
 */
public static void main(String[] args) {
    MongoConnectionPropertiesLoader.load();
    Injector injector = Guice.createInjector(new LotteryModule());
    LotteryAdministration administartion = injector.getInstance(LotteryAdministration.class);
    LotteryService service = injector.getInstance(LotteryService.class);
    SampleData.submitTickets(service, 20);
    try (Scanner scanner = new Scanner(System.in)) {
        boolean exit = false;
        while (!exit) {
            printMainMenu();
            String cmd = readString(scanner);
            if ("1".equals(cmd)) {
                administartion.getAllSubmittedTickets().forEach((k, v) -> LOGGER.info("Key: {}, Value: {}", k, v));
            } else if ("2".equals(cmd)) {
                LotteryNumbers numbers = administartion.performLottery();
                LOGGER.info("The winning numbers: {}", numbers.getNumbersAsString());
                LOGGER.info("Time to reset the database for next round, eh?");
            } else if ("3".equals(cmd)) {
                administartion.resetLottery();
                LOGGER.info("The lottery ticket database was cleared.");
            } else if ("4".equals(cmd)) {
                exit = true;
            } else {
                LOGGER.info("Unknown command: {}", cmd);
            }
        }
    }
}
Also used : Scanner(java.util.Scanner) LotteryNumbers(com.iluwatar.hexagonal.domain.LotteryNumbers) Injector(com.google.inject.Injector) LotteryAdministration(com.iluwatar.hexagonal.domain.LotteryAdministration) LotteryModule(com.iluwatar.hexagonal.module.LotteryModule) LotteryService(com.iluwatar.hexagonal.domain.LotteryService)

Example 2 with LotteryModule

use of com.iluwatar.hexagonal.module.LotteryModule in project java-design-patterns by iluwatar.

the class ConsoleLottery method main.

/**
 * Program entry point
 */
public static void main(String[] args) {
    MongoConnectionPropertiesLoader.load();
    Injector injector = Guice.createInjector(new LotteryModule());
    LotteryService service = injector.getInstance(LotteryService.class);
    WireTransfers bank = injector.getInstance(WireTransfers.class);
    try (final Scanner scanner = new Scanner(System.in)) {
        boolean exit = false;
        while (!exit) {
            printMainMenu();
            String cmd = readString(scanner);
            if ("1".equals(cmd)) {
                queryLotteryAccountFunds(bank, scanner);
            } else if ("2".equals(cmd)) {
                addFundsToLotteryAccount(bank, scanner);
            } else if ("3".equals(cmd)) {
                submitTicket(service, scanner);
            } else if ("4".equals(cmd)) {
                checkTicket(service, scanner);
            } else if ("5".equals(cmd)) {
                exit = true;
            } else {
                LOGGER.info("Unknown command");
            }
        }
    }
}
Also used : Scanner(java.util.Scanner) Injector(com.google.inject.Injector) WireTransfers(com.iluwatar.hexagonal.banking.WireTransfers) LotteryModule(com.iluwatar.hexagonal.module.LotteryModule) LotteryService(com.iluwatar.hexagonal.domain.LotteryService)

Aggregations

Injector (com.google.inject.Injector)2 LotteryService (com.iluwatar.hexagonal.domain.LotteryService)2 LotteryModule (com.iluwatar.hexagonal.module.LotteryModule)2 Scanner (java.util.Scanner)2 WireTransfers (com.iluwatar.hexagonal.banking.WireTransfers)1 LotteryAdministration (com.iluwatar.hexagonal.domain.LotteryAdministration)1 LotteryNumbers (com.iluwatar.hexagonal.domain.LotteryNumbers)1