Game schedule #14

Merged
schrom01 merged 5 commits from GameSchedule into main 2022-05-01 21:36:16 +02:00
4 changed files with 53 additions and 0 deletions
Showing only changes of commit b09929da19 - Show all commits

View File

@ -3,4 +3,5 @@ package ch.zhaw.projekt2.turnierverwaltung;
public interface Participant { public interface Participant {
String getName(); String getName();
void setName(String name); void setName(String name);
boolean equals(Participant participant);
} }

View File

@ -18,4 +18,10 @@ public class Player extends Person implements Participant{
public void setDateOfBirth(Date dateOfBirth) { public void setDateOfBirth(Date dateOfBirth) {
this.dateOfBirth = dateOfBirth; this.dateOfBirth = dateOfBirth;
} }
@Override
public boolean equals(Participant participant) {
return getClass().equals(participant.getClass()) && getName().equals(participant.getName()) &&
getFirstName().equals(((Player) participant).getFirstName());
}
} }

View File

@ -27,6 +27,11 @@ public class Team implements Participant {
this.name = name; this.name = name;
} }
@Override
public boolean equals(Participant participant) {
return getClass().equals(participant.getClass()) && name.equals(participant.getName());
}
public Person getContactPerson() { public Person getContactPerson() {
return contactPerson; return contactPerson;
} }

View File

@ -4,11 +4,14 @@ import javafx.collections.FXCollections;
import javafx.collections.ObservableList; import javafx.collections.ObservableList;
import java.io.Serializable; import java.io.Serializable;
import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.List;
public class Tournament implements Serializable { public class Tournament implements Serializable {
private String name; private String name;
private Type type; private Type type;
private List<Participant> participants;
@ -21,6 +24,22 @@ public class Tournament implements Serializable {
setName(name); setName(name);
setType(type); setType(type);
participants = new ArrayList<>();
}
public void addParticipant(Participant newParticipant) throws ParticipantExistsException {
for(Participant participant : participants){
if(participant.equals(newParticipant)){
throw new ParticipantExistsException("A Participant with the same Name exists already.");
}
}
participants.add(newParticipant);
}
public void removeParticipant(Participant participant) throws ParticipantNotExistsException {
if(!participants.contains(participant)){
throw new ParticipantNotExistsException("The given Participant is not part of this Tournament");
}
} }
public String getName() { public String getName() {
@ -82,5 +101,27 @@ public class Tournament implements Serializable {
} }
public class ParticipantExistsException extends Exception {
public ParticipantExistsException() {
super();
}
public ParticipantExistsException(String errorMessage) {
super(errorMessage);
}
}
public class ParticipantNotExistsException extends Exception {
public ParticipantNotExistsException() {
super();
}
public ParticipantNotExistsException(String errorMessage) {
super(errorMessage);
}
}
} }