From abb11a3d567e3398e1fa141ce4c688b7f6c9b833 Mon Sep 17 00:00:00 2001 From: Tvesha Shah Date: Mon, 22 Jan 2024 09:03:13 -0500 Subject: [PATCH 1/2] demo_0 --- .../ca/mcscert/se2aa4/demos/tennis/Main.java | 64 +++++++++++++++---- .../ca/mcscert/se2aa4/demos/tennis/Match.java | 12 ++++ 2 files changed, 63 insertions(+), 13 deletions(-) create mode 100644 src/main/java/ca/mcscert/se2aa4/demos/tennis/Match.java diff --git a/src/main/java/ca/mcscert/se2aa4/demos/tennis/Main.java b/src/main/java/ca/mcscert/se2aa4/demos/tennis/Main.java index 16f7dac..173895c 100644 --- a/src/main/java/ca/mcscert/se2aa4/demos/tennis/Main.java +++ b/src/main/java/ca/mcscert/se2aa4/demos/tennis/Main.java @@ -8,27 +8,65 @@ public class Main { - public static int PLAYER1_STRENGTH; - public static int PLAYER2_STRENGTH; + //public static int PLAYER1_STRENGTH; + //public static int PLAYER2_STRENGTH; public static void main(String[] args) { + +//stopping errors and ctching stuff System.out.println("** Starting Tennis Counter Assistant"); System.out.println("**** Reading Command-Line Arguments"); + + try{ + Configuration config = configure(args); + System.out.println(config); + + Match theMatch = new Match(config.p1Strength(), config.p2Strength()); + String winner = theMatch.play(); + + System.out.println("Winner is:" + winner); //only one that should stay system print + + }catch(ParseException pe){ + System.err.println(pe.getMessage()); + System.exit(1); + } + + System.out.println("**** Starting game"); + System.out.println("** TODO..."); + System.out.println("** Closing Tennis Counter Assistant"); + } + + private static Configuration configure(String[] args) throws ParseException{ + + //configure system through otions + //assuming idea world Options options = new Options(); options.addOption("p1", true, "Strength of Player 1 in [0,100]"); options.addOption("p2", true, "Strength of Player 2 in [0,100]"); + CommandLineParser parser = new DefaultParser(); - try { - CommandLine cmd = parser.parse(options, args); - PLAYER1_STRENGTH = Integer.parseInt(cmd.getOptionValue("p1","50")); - System.out.println("****** P1's Strength is " + PLAYER1_STRENGTH+"/100"); - PLAYER2_STRENGTH = Integer.parseInt(cmd.getOptionValue("p2","50")); - System.out.println("****** P2's Strength is " + PLAYER2_STRENGTH+"/100"); - } catch (ParseException pe) { - System.err.println("An error has occurred"); + + CommandLine cmd = parser.parse(options, args); + + Integer p1s = Integer.parseInt(cmd.getOptionValue("p1","50")); + System.out.println("****** P1's Strength is " + p1s+"/100"); + Integer p2s = Integer.parseInt(cmd.getOptionValue("p2","50")); + System.out.println("****** P2's Strength is " + p2s+"/100"); + + return new Configuration(p1s,p2s); + + } + + + private record Configuration(Integer p1Strength, Integer p2Strength) { + //what i want in specification is strength of player from 0-100 + Configuration{ + + if (p1Strength <0 || p1Strength >100) + throw new IllegalArgumentException("P1's Strenght is not b/w 0-100:" + p1Strength); + + if (p2Strength <0 || p2Strength >100) + throw new IllegalArgumentException("P2's Strenght is not b/w 0-100:" + p2Strength); } - System.out.println("**** Starting game"); - System.out.println("** TODO..."); - System.out.println("** Closing Tennis Counter Assistant"); } } diff --git a/src/main/java/ca/mcscert/se2aa4/demos/tennis/Match.java b/src/main/java/ca/mcscert/se2aa4/demos/tennis/Match.java new file mode 100644 index 0000000..bba3662 --- /dev/null +++ b/src/main/java/ca/mcscert/se2aa4/demos/tennis/Match.java @@ -0,0 +1,12 @@ +package ca.mcscert.se2aa4.demos.tennis; + +public class Match{ + public Match(Integer p1Strength, Integer p2Strength){ + + + } + + public String play(){ + return " No winner... yet"; + } +} \ No newline at end of file From 7aca5fb28e902b6cc8863ae7c4d34b36ec7eb347 Mon Sep 17 00:00:00 2001 From: Tvesha Shah Date: Mon, 22 Jan 2024 09:19:55 -0500 Subject: [PATCH 2/2] names --- src/main/java/ca/mcscert/se2aa4/demos/tennis/Match.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/main/java/ca/mcscert/se2aa4/demos/tennis/Match.java b/src/main/java/ca/mcscert/se2aa4/demos/tennis/Match.java index bba3662..0dad8b5 100644 --- a/src/main/java/ca/mcscert/se2aa4/demos/tennis/Match.java +++ b/src/main/java/ca/mcscert/se2aa4/demos/tennis/Match.java @@ -1,8 +1,12 @@ package ca.mcscert.se2aa4.demos.tennis; public class Match{ - public Match(Integer p1Strength, Integer p2Strength){ + public static final String P1_name = "p1"; + + public static final String P2_name = "p2"; + + public Match(Integer p1Strength, Integer p2Strength){ }