From c256a7b0fb085c77eb520e991451cf33a1d3c497 Mon Sep 17 00:00:00 2001 From: Andrew Regan Date: Sat, 15 Jan 2022 22:54:13 +0000 Subject: [PATCH] Fix budget validation; restore "keep same allocations" --- 27_Civil_War/java/src/CivilWar.java | 38 ++++++++++++++++------------- 1 file changed, 21 insertions(+), 17 deletions(-) diff --git a/27_Civil_War/java/src/CivilWar.java b/27_Civil_War/java/src/CivilWar.java index ad909f2c..7b8d8b4c 100644 --- a/27_Civil_War/java/src/CivilWar.java +++ b/27_Civil_War/java/src/CivilWar.java @@ -190,27 +190,31 @@ public class CivilWar { currentResources = resources.union; } - out.println("HOW MUCH DO YOU WISH TO SPEND FOR"); - out.print("- FOOD...... ? "); - var F = terminalInput.nextInt(); - if (F == 0) { - if (this.revenue.confederate != 0) { - out.println("ASSUME YOU WANT TO KEEP SAME ALLOCATIONS"); - out.println(); + var validInputs = false; + while (!validInputs) { + out.println("HOW MUCH DO YOU WISH TO SPEND FOR"); + out.print("- FOOD...... ? "); + var food = terminalInput.nextInt(); + if (food == 0) { + if (this.revenue.confederate != 0) { + out.println("ASSUME YOU WANT TO KEEP SAME ALLOCATIONS"); + out.println(); + } + } else { + currentResources.food = food; } - } - currentResources.food = F; + out.print("- SALARIES.. ? "); + currentResources.salaries = terminalInput.nextInt(); - out.print("- SALARIES.. ? "); - currentResources.salaries = terminalInput.nextInt(); + out.print("- AMMUNITION ? "); + currentResources.ammunition = terminalInput.nextInt(); // FIXME Retry if -ve - out.print("- AMMUNITION ? "); - currentResources.ammunition = terminalInput.nextInt(); // FIXME Retry if -ve - - if (currentResources.getTotal() > currentResources.budget) { - out.println("THINK AGAIN! YOU HAVE ONLY $" + currentResources.budget); - // FIXME Redo inputs from Food + if (currentResources.getTotal() > currentResources.budget) { + out.println("THINK AGAIN! YOU HAVE ONLY $" + currentResources.budget); + } else { + validInputs = true; + } } }