Witam
Mam do was dwa pytanka:
- Posiadam taki konstruktor
public Match(FootballClub teamA, FootballClub teamB, int teamAScore, int teamBScore, Date date) {
this.teamA = teamA;
this.teamB = teamB;
this.teamAScore = teamAScore;
this.TeamBScore = teamBScore;
this.date = date;
if(teamAScore>teamBScore){
teamA.setWinsCount(teamA.getWinsCount()+1);
teamA.setScoredGoalsCount(teamA.getScoredGoalsCount()+teamAScore);
teamA.setRecivedGoalsCount(teamA.getRecivedGoalsCount()+teamBScore);
teamB.setDefeatsCount(teamB.getDefeatsCount()+1);
teamB.setScoredGoalsCount(teamB.getScoredGoalsCount()+teamBScore);
teamA.setRecivedGoalsCount(teamA.getRecivedGoalsCount()+teamBScore);
teamA.setPoints(teamA.getPoints()+3);
}
else if(teamAScore==teamBScore){
teamA.setDrawsCount(teamA.getDrawsCount()+1);
teamB.setDrawsCount(teamB.getDrawsCount()+1);
teamA.setRecivedGoalsCount(teamA.getRecivedGoalsCount()+teamBScore);
teamA.setRecivedGoalsCount(teamA.getRecivedGoalsCount()+teamBScore);
teamA.setPoints(teamA.getPoints()+1);
teamB.setPoints(teamB.getPoints()+1);
}
else if(teamBScore>teamAScore){
teamB.setWinsCount(teamB.getWinsCount()+1);
teamB.setScoredGoalsCount(teamB.getScoredGoalsCount()+teamBScore);
teamB.setRecivedGoalsCount(teamB.getRecivedGoalsCount()+teamAScore);
teamA.setDefeatsCount(teamA.getDefeatsCount()+1);
teamA.setScoredGoalsCount(teamA.getScoredGoalsCount()+teamAScore);
teamB.setRecivedGoalsCount(teamB.getRecivedGoalsCount()+teamAScore);
teamB.setPoints(teamB.getPoints()+3);
}
}
Czy umieszczenie takiej logiki w nim jest zgodne z normami, konwencjami, czy powinna być gdzie indziej?
2 Mam taką metodę i wywołanie
private Date setDate(){
System.out.println("Podaj datę: (dd-mm-rrrr)");
String line = scanner.nextLine();
Date date = null;
try {
date = new SimpleDateFormat("dd-MM-yyyy").parse(line);
} catch (ParseException ex) {
System.out.println("niepoprawny format daty");
}
return date;
}
private void playMatch() {
Date date;
do {
date = setDate();
}
while(date==null);
}
Czy jest to dobre rozwiązanie, jeśli chce pytać aż do uzyskania poprawnej odpowiedzi? Czy jest lepsza opcja?
Z góry dzięki