MatchesAdapter class: public class MatchesAdapter { Connection connection; public MatchesAdapter(Connection conn, Boolean reset) throws SQLException { connection = conn; if (reset) { Statement stmt = connection.createStatement(); try { // Remove tables if database tables have been created. // This will throw an exception if the tables do not exist stmt.execute("DROP TABLE Matches"); // then do finally } catch (SQLException ex) { // No need to report an error. // The table simply did not exist. // do finally to create it } finally { // Create the table of Matches stmt.execute("CREATE TABLE Matches (" + "MatchNumber INT NOT NULL PRIMARY KEY, " + "HomeTeam CHAR(15) NOT NULL REFERENCES Teams (TeamName), " + "VisitorTeam CHAR(15) NOT NULL REFERENCES Teams (TeamName), " + "HomeTeamScore INT, " + "VisitorTeamScore INT " + ")"); populateSamples(); } } } private void populateSamples() throws SQLException{ // Create a listing of the matches to be played this.insertMatch(1, "Astros", "Brewers"); this.insertMatch(2, "Brewers", "Cubs"); this.insertMatch(3, "Cubs", "Astros"); } public int getMax() throws SQLException { int num = 0; // Add your work code here for Task #3 return num; } public void insertMatch(int num, String home, String visitor) throws SQLException { Statement stmt = connection.createStatement(); stmt.executeUpdate("INSERT INTO Matches (MatchNumber, HomeTeam, VisitorTeam, HomeTeamScore, VisitorTeamScore) " + "VALUES (" + num + " , '" + home + "' , '" + visitor + "', 0, 0)"); } // Get all Matches public ObservableList getMatchesList() throws SQLException { ObservableList matchesList = FXCollections.observableArrayList(); //Add code for Task 2 here return matchesList; } // Get a String list of matches to populate the ComboBox used in Task #4. public ObservableList getMatchesNamesList() throws SQLException { ObservableList list = FXCollections.observableArrayList(); ResultSet rs; // Create a Statement object // Create a string with a SELECT statement // Execute the statement and return the result // Loop the entire rows of rs and set the string values of list return list; } public void setTeamsScore(int matchNumber, int hScore, int vScore) throws SQLException { // Add your code here for Task #4 } }
please help with task 2. Thanks
T-ball Teams 3.2 Task 2: Retrieve Information Using SQL Select the Menu Item View Teams Standings. Your output should be as follows: File View Add Abo . Team Standings Current Teams Standings Current Teams Standings Team Name Wins Losses Ties Astros 0 0 0 Brewers 0 0 0 0 0 0 Cubs Marlins 0 0 0 . Write the implementation for the get Matches List() method in Matches Adapter.java 1. Write an SQL statement to select all columns from the Matches table. 2. Execute the query by sending the SQL statement to the DBMS. 3. Use a while loop to add the contents of the result set to matches List. 4. Compile and run the program. Select the Menu Item View Matches. 5. Your output should be as follows: package TennisBallGames; // import the required libraries public class AddMatchController implements Initializable { // Some @FXML declarations // Some local variable declarations // The data variable is used to populate the ComboBoxs final ObservableList
data = FXCollections.observableArrayList(); // To reference the models inside the controller private MatchesAdapter matchesAdapter; private TeamsAdapter teams Adapter; public void setModel (MatchesAdapter match, TeamsAdapter team) { matchesAdapter = match; teams Adapter = team; buildComboBoxData(); } @FXML public void cancel() { Stage stage = (Stage) cancelBtn.getScene().getWindow(); stage.close(); } @FXML public void save() { // Do some work here } public void buildComboBoxData() { try { data.addAll(teams Adapter.getTeams Names ()); } catch (SQLException ex) { displayAlert("ERROR: + ex.getMessage()); } } @Override public void initialize(URL url, ResourceBundle rb) { home TeamBox.setItems (data); visitorTeamBox.setItems (data); } 11 6. Note that, the match Number is a serial number generated automatically and equal to the maximum match number in the table plus one. Hint, you need to write a new method in the Matches Adapter class (you may name it get Max() that you will invoke from the Add Match Controller class to generate the serial number, it uses the SQL command: SELECT MAX(Match Number) FROM Matches 7. Write the get Teams Names() method in the Team Adapter class. 8. Uncomment the code of the method add Match() n the MainForm Controller.java. Compile and run the program. Add a match between Braves and Cubs and then show the list of matches from the menu View Matches. Your output should now look like: SE 2203b - Software Design Laboratory 5 Current Matches Schedule List of matches and scores Match Number Home Team Home Score Visitor Team Visitor Score 1 Astros 0 Brewers 0 2 Brewers 0 Cubs 0 3 Cubs 0 Astros 0 4 Braves 0 Cubs 0 the Teams table for one of the teams, increment it, and update the table for that team. Do the same for the opposing team. 7. Uncomment the code of the method addScore() n the MainForm Controller.java. Compile and run the program. Add the following match score using the menu option Add Score. GameNumber HomeTeam Home TeamScore VisitorTeam VisitorTeamScore 1 Astros 5 Brewers 3 2 Brewers 4 Cubs 4 3 Cubs 1 Astros 6 8. Select the menu option View Teams Standings to view the team standings and the menu option View Matches to see the scores. Your output should now be: Current Teams Standings Current Matches Schedule Current Teams Standings List of matches and scores Team Name Wins Losses Ties Match Number Home Team Home Score Visitor Team Visitor Score 2 0 0 Astros Marlins 1 Astros 5 Brewers 3 0 0 0 2 Brewers 4 Cubs 4 Brewers 0 1 1 3 Cubs 1 Astros 6 Cubs 0 1 1 4 Braves 0 Cubs 0 Braves 0 0 0 T-ball Teams 3.2 Task 2: Retrieve Information Using SQL Select the Menu Item View Teams Standings. Your output should be as follows: File View Add Abo . Team Standings Current Teams Standings Current Teams Standings Team Name Wins Losses Ties Astros 0 0 0 Brewers 0 0 0 0 0 0 Cubs Marlins 0 0 0 . Write the implementation for the get Matches List() method in Matches Adapter.java 1. Write an SQL statement to select all columns from the Matches table. 2. Execute the query by sending the SQL statement to the DBMS. 3. Use a while loop to add the contents of the result set to matches List. 4. Compile and run the program. Select the Menu Item View Matches. 5. Your output should be as follows: package TennisBallGames; // import the required libraries public class AddMatchController implements Initializable { // Some @FXML declarations // Some local variable declarations // The data variable is used to populate the ComboBoxs final ObservableList data = FXCollections.observableArrayList(); // To reference the models inside the controller private MatchesAdapter matchesAdapter; private TeamsAdapter teams Adapter; public void setModel (MatchesAdapter match, TeamsAdapter team) { matchesAdapter = match; teams Adapter = team; buildComboBoxData(); } @FXML public void cancel() { Stage stage = (Stage) cancelBtn.getScene().getWindow(); stage.close(); } @FXML public void save() { // Do some work here } public void buildComboBoxData() { try { data.addAll(teams Adapter.getTeams Names ()); } catch (SQLException ex) { displayAlert("ERROR: + ex.getMessage()); } } @Override public void initialize(URL url, ResourceBundle rb) { home TeamBox.setItems (data); visitorTeamBox.setItems (data); } 11 6. Note that, the match Number is a serial number generated automatically and equal to the maximum match number in the table plus one. Hint, you need to write a new method in the Matches Adapter class (you may name it get Max() that you will invoke from the Add Match Controller class to generate the serial number, it uses the SQL command: SELECT MAX(Match Number) FROM Matches 7. Write the get Teams Names() method in the Team Adapter class. 8. Uncomment the code of the method add Match() n the MainForm Controller.java. Compile and run the program. Add a match between Braves and Cubs and then show the list of matches from the menu View Matches. Your output should now look like: SE 2203b - Software Design Laboratory 5 Current Matches Schedule List of matches and scores Match Number Home Team Home Score Visitor Team Visitor Score 1 Astros 0 Brewers 0 2 Brewers 0 Cubs 0 3 Cubs 0 Astros 0 4 Braves 0 Cubs 0 the Teams table for one of the teams, increment it, and update the table for that team. Do the same for the opposing team. 7. Uncomment the code of the method addScore() n the MainForm Controller.java. Compile and run the program. Add the following match score using the menu option Add Score. GameNumber HomeTeam Home TeamScore VisitorTeam VisitorTeamScore 1 Astros 5 Brewers 3 2 Brewers 4 Cubs 4 3 Cubs 1 Astros 6 8. Select the menu option View Teams Standings to view the team standings and the menu option View Matches to see the scores. Your output should now be: Current Teams Standings Current Matches Schedule Current Teams Standings List of matches and scores Team Name Wins Losses Ties Match Number Home Team Home Score Visitor Team Visitor Score 2 0 0 Astros Marlins 1 Astros 5 Brewers 3 0 0 0 2 Brewers 4 Cubs 4 Brewers 0 1 1 3 Cubs 1 Astros 6 Cubs 0 1 1 4 Braves 0 Cubs 0 Braves 0 0 0