Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

demo_0 #28

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 51 additions & 13 deletions src/main/java/ca/mcscert/se2aa4/demos/tennis/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
}
16 changes: 16 additions & 0 deletions src/main/java/ca/mcscert/se2aa4/demos/tennis/Match.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package ca.mcscert.se2aa4.demos.tennis;

public class Match{

public static final String P1_name = "p1";

public static final String P2_name = "p2";

public Match(Integer p1Strength, Integer p2Strength){

}

public String play(){
return " No winner... yet";
}
}