Advertisement
El_Azar99

Deo koda

Apr 14th, 2024
852
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.28 KB | Source Code | 0 0
  1. int hrs = match.getSchedule().getDateTime().getHour();
  2. int min = match.getSchedule().getDateTime().getMinute();
  3. if ((hrs > 20 || (hrs == 20 && min > 0)) && (this instanceof Stadium)) {
  4.     throw new AddingMatchException("Match starts too late to be added to Stadium, try earlier than 8pm!");
  5. } else {
  6.     ArrayList<Athlete> athletesList = match.getAthletesList();
  7.     if (athletesList == null || athletesList.isEmpty()) {
  8.         throw new SportDisciplineException("No athletes assigned to the match.");
  9.     }
  10.     for (Athlete athlete : athletesList) {
  11.         if (athlete.getDiscipline() != this.getDiscipline()) {
  12.             throw new SportDisciplineException("Unable to add the match to the venue, as the venue accepts matches of discipline " + this.getDiscipline() + ", and athlete " + athlete.getName() + " assigned to the match competes in discipline " + athlete.getDiscipline() + ".");
  13.         }
  14.     }
  15.  
  16.     for (int i = 0; i < listOfMatches.length; i++) {
  17.         if (listOfMatches[i] == null) {
  18.             listOfMatches[i] = match;
  19.             System.out.println("Successfully added match: \n" + match.toString());
  20.             break;
  21.         } else if (i == listOfMatches.length - 1) {
  22.             throw new AddingMatchException("List of matches is full!");
  23.         }
  24.     }
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement