From ac8facda0d8b098c2be7c8428c3a8eb26c01c2d6 Mon Sep 17 00:00:00 2001 From: Maksym Volkov Date: Mon, 25 Feb 2019 18:19:40 +0200 Subject: [PATCH] add product to new check if it`s already closed --- src/checkout/CheckoutService.java | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/checkout/CheckoutService.java b/src/checkout/CheckoutService.java index 5a93a7b..3df430e 100644 --- a/src/checkout/CheckoutService.java +++ b/src/checkout/CheckoutService.java @@ -9,15 +9,19 @@ public void openCheck() { } public void addProduct(Product product) { - if (check == null) { + if (isClosed()) { openCheck(); } check.addProduct(product); } public Check closeCheck() { - Check closedCheck = check; + final Check result = check; check = null; - return closedCheck; + return result; + } + + private boolean isClosed() { + return check == null; } }