diff options
| author | Kostya <mail@sartin.in> | 2026-08-14 20:54:31 +0000 |
|---|---|---|
| committer | Kostya <mail@sartin.in> | 2026-08-14 20:54:31 +0000 |
| commit | d77a70c48865592be9029aeb0c83b36c162ea31a (patch) | |
| tree | 219adfbeb1991b71433d5d36375e93fe73f81dec | |
| parent | 001f6444fec8fcd5312028cfdae90f4f93424559 (diff) | |
| download | guess-market-d77a70c48865592be9029aeb0c83b36c162ea31a.tar.gz guess-market-d77a70c48865592be9029aeb0c83b36c162ea31a.tar.xz guess-market-d77a70c48865592be9029aeb0c83b36c162ea31a.zip | |
Switch TradingMechanism quantities to int, add yes/no and select prompts
TradingMechanism's q/quantity params move from long/long[] to int/int[]
to match the rest of the domain (Trade.quantity, Option counts, etc.
are already int).
Add InputProcessor.readYesNo and readSelect for upcoming menu commands
that need a confirm prompt or a pick-from-list prompt.
4 files changed, 35 insertions, 6 deletions
diff --git a/service/src/main/java/market/guess/service/mechanism/LmsrTradingMechanism.java b/service/src/main/java/market/guess/service/mechanism/LmsrTradingMechanism.java index 02a63df..1904a04 100644 --- a/service/src/main/java/market/guess/service/mechanism/LmsrTradingMechanism.java +++ b/service/src/main/java/market/guess/service/mechanism/LmsrTradingMechanism.java | |||
| @@ -23,13 +23,13 @@ public final class LmsrTradingMechanism implements TradingMechanism { | |||
| 23 | } | 23 | } |
| 24 | 24 | ||
| 25 | @Override | 25 | @Override |
| 26 | public BigDecimal costOfBuying(long[] q, int optionIndex, long quantity) { | 26 | public BigDecimal costOfBuying(int[] q, int optionIndex, int quantity) { |
| 27 | // TODO Auto-generated method stub | 27 | // TODO Auto-generated method stub |
| 28 | throw new UnsupportedOperationException("Unimplemented method 'costOfBuying'"); | 28 | throw new UnsupportedOperationException("Unimplemented method 'costOfBuying'"); |
| 29 | } | 29 | } |
| 30 | 30 | ||
| 31 | @Override | 31 | @Override |
| 32 | public double[] prices(long[] q) { | 32 | public double[] prices(int[] q) { |
| 33 | // TODO Auto-generated method stub | 33 | // TODO Auto-generated method stub |
| 34 | throw new UnsupportedOperationException("Unimplemented method 'prices'"); | 34 | throw new UnsupportedOperationException("Unimplemented method 'prices'"); |
| 35 | } | 35 | } |
diff --git a/service/src/main/java/market/guess/service/mechanism/OrderBookTradingMechanism.java b/service/src/main/java/market/guess/service/mechanism/OrderBookTradingMechanism.java index 62feb02..5807e45 100644 --- a/service/src/main/java/market/guess/service/mechanism/OrderBookTradingMechanism.java +++ b/service/src/main/java/market/guess/service/mechanism/OrderBookTradingMechanism.java | |||
| @@ -27,13 +27,13 @@ public final class OrderBookTradingMechanism implements TradingMechanism { | |||
| 27 | } | 27 | } |
| 28 | 28 | ||
| 29 | @Override | 29 | @Override |
| 30 | public BigDecimal costOfBuying(long[] q, int optionIndex, long quantity) { | 30 | public BigDecimal costOfBuying(int[] q, int optionIndex, int quantity) { |
| 31 | // TODO Auto-generated method stub | 31 | // TODO Auto-generated method stub |
| 32 | throw new UnsupportedOperationException("Unimplemented method 'costOfBuying'"); | 32 | throw new UnsupportedOperationException("Unimplemented method 'costOfBuying'"); |
| 33 | } | 33 | } |
| 34 | 34 | ||
| 35 | @Override | 35 | @Override |
| 36 | public double[] prices(long[] q) { | 36 | public double[] prices(int[] q) { |
| 37 | // TODO Auto-generated method stub | 37 | // TODO Auto-generated method stub |
| 38 | throw new UnsupportedOperationException("Unimplemented method 'prices'"); | 38 | throw new UnsupportedOperationException("Unimplemented method 'prices'"); |
| 39 | } | 39 | } |
diff --git a/service/src/main/java/market/guess/service/mechanism/TradingMechanism.java b/service/src/main/java/market/guess/service/mechanism/TradingMechanism.java index d6e38bc..c2fc865 100644 --- a/service/src/main/java/market/guess/service/mechanism/TradingMechanism.java +++ b/service/src/main/java/market/guess/service/mechanism/TradingMechanism.java | |||
| @@ -9,7 +9,7 @@ public interface TradingMechanism { | |||
| 9 | 9 | ||
| 10 | BigDecimal openingCost(int optionCount); | 10 | BigDecimal openingCost(int optionCount); |
| 11 | 11 | ||
| 12 | BigDecimal costOfBuying(long[] q, int optionIndex, long quantity); | 12 | BigDecimal costOfBuying(int[] q, int optionIndex, int quantity); |
| 13 | 13 | ||
| 14 | double[] prices(long[] q); | 14 | double[] prices(int[] q); |
| 15 | } | 15 | } |
diff --git a/ui-console/src/main/java/market/guess/ui/console/io/InputProcessor.java b/ui-console/src/main/java/market/guess/ui/console/io/InputProcessor.java index 4889c36..fc5422f 100644 --- a/ui-console/src/main/java/market/guess/ui/console/io/InputProcessor.java +++ b/ui-console/src/main/java/market/guess/ui/console/io/InputProcessor.java | |||
| @@ -1,6 +1,8 @@ | |||
| 1 | package market.guess.ui.console.io; | 1 | package market.guess.ui.console.io; |
| 2 | 2 | ||
| 3 | import java.util.List; | ||
| 3 | import java.util.Scanner; | 4 | import java.util.Scanner; |
| 5 | import java.util.function.Function; | ||
| 4 | 6 | ||
| 5 | public final class InputProcessor { | 7 | public final class InputProcessor { |
| 6 | private final Scanner scanner = new Scanner(System.in); | 8 | private final Scanner scanner = new Scanner(System.in); |
| @@ -67,6 +69,33 @@ public final class InputProcessor { | |||
| 67 | } | 69 | } |
| 68 | } | 70 | } |
| 69 | 71 | ||
| 72 | public boolean readYesNo(String prompt) { | ||
| 73 | while (true) { | ||
| 74 | var raw = readLine("%s [Y/N]: ".formatted(prompt)).toLowerCase(); | ||
| 75 | |||
| 76 | switch (raw) { | ||
| 77 | case "y", "yes" -> { | ||
| 78 | return true; | ||
| 79 | } | ||
| 80 | case "n", "no" -> { | ||
| 81 | return false; | ||
| 82 | } | ||
| 83 | default -> IO.println("Please answer y/yes or n/no."); | ||
| 84 | } | ||
| 85 | } | ||
| 86 | } | ||
| 87 | |||
| 88 | public <T> T readSelect(String prompt, List<T> items, Function<T, String> function) { | ||
| 89 | |||
| 90 | for (var i = 0; i < items.size(); i++) { | ||
| 91 | IO.println(" [%d]->> %s".formatted(i + 1, function.apply(items.get(i)))); | ||
| 92 | } | ||
| 93 | |||
| 94 | var pick = readInt(prompt, 1, items.size()); | ||
| 95 | |||
| 96 | return items.get(pick - 1); | ||
| 97 | } | ||
| 98 | |||
| 70 | private String nextLine() { | 99 | private String nextLine() { |
| 71 | return scanner.hasNextLine() ? scanner.nextLine() : null; | 100 | return scanner.hasNextLine() ? scanner.nextLine() : null; |
| 72 | } | 101 | } |