This project is a simple Java library designed to manage and display live scores for football matches during the World Cup. It allows for adding matches, updating scores, finishing matches, and retrieving a summary of ongoing matches.
- Start new matches with initial scores of 0-0.
- Update scores for ongoing matches.
- Finish matches and remove them from the scoreboard.
- Retrieve a summary of ongoing matches ordered by total score and start time.
- Java 21
- JUnit 5 (for testing)
- Maven
- Clone the repository:
git clone <repository_url>
- Navigate to the project directory:
cd <project_directory>
- Build the project:
mvn clean install
- Create a Scoreboard Instance:
Scoreboard scoreboard = new Scoreboard();
- Start a New Match:
scoreboard.startMatch("Home Team", "Away Team");
- Update Scores:
scoreboard.updateScore("Home Team", 1, 2); // Home team 1, Away team 2
- Finish a Match:
scoreboard.finishMatch("Home Team");
- Get Matches Summary:
List<Match> summary = scoreboard.getMatchesSummary();
for (Match match : summary) {
System.out.println(match);
}
Here’s a complete example of using the library:
public class Main {
public static void main(String[] args) {
Scoreboard scoreboard = new Scoreboard();
// Start matches
scoreboard.startMatch("Mexico", "Canada");
scoreboard.startMatch("Spain", "Brazil");
// Update scores
scoreboard.updateScore("Mexico", 0, 5);
scoreboard.updateScore("Spain", 10, 2);
// Get summary
List<Match> summary = scoreboard.getMatchesSummary();
for (Match match : summary) {
System.out.println(match);
}
}
}
To run the tests for this library, ensure you have JUnit 5 configured in your project, and then execute:
mvn test
- Each match is uniquely identified by the home team name.
- The library does not implement a persistence layer; all data is stored in memory.
Contributions are welcome! Please create a pull request or submit issues for improvements.
- Enhance Error Handling: Consider adding error handling for cases like updating scores for non-existing matches.
- Improve Validation: Validate team names and scores before processing.
- Add Additional Features: Consider adding functionality for features like getting the list of finished matches or getting a specific match by team name.