-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSportEvent.java
More file actions
74 lines (51 loc) · 3 KB
/
SportEvent.java
File metadata and controls
74 lines (51 loc) · 3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package project3;
import java.lang.String;
import java.lang.Math;
import java.util.Date;
import java.text.ParseException;
import java.util.ArrayList;
import project3.Event;
import project3.Game;
public class SportEvent extends Event implements Game {
private String[] teams = new String[2];
private int[] scores = new int[2];
private int winnerIndex;
private int loserIndex;
private String league;
private static ArrayList<Event> eventList = new ArrayList<Event>();
protected SportEvent() {}
protected SportEvent(String name, String place, Date dateTime, int audience, int cost, int revenue, int profit, String[] teams, int[] scores, String league) throws ParseException {
super(name, place, dateTime, audience, cost, revenue, profit);
this.setTeams (teams );
this.setScores(scores );
this.setLeague(league );
SportEvent event = this;
SportEvent.eventList.add(event);
} // SportEvent()
public final void setTeams(String[] teams) {this.teams = teams;}
public String[] getTeams() {return this.teams;}
public final void setScores(int[] scores) {
this.scores = scores;
if (scores[0] > scores[1]) this.winnerIndex = 0;
else if (scores[0] < scores[1]) this.winnerIndex = 1;
else this.winnerIndex = (Math.random() < 0.5) ? 0 : 1;
this.loserIndex = (this.winnerIndex == 1) ? 0 : 1;
} // setScores()
public int[] getScores() {return this.scores;}
public int getWinnerIndex() {return this.winnerIndex;}
public int getLoserIndex () {return this.loserIndex;}
public final void setLeague(String league) {this.league = league;}
public String getLeague() {return this.league;}
public static ArrayList getEventList() {return SportEvent.eventList;} // static method, cannot be over-ridden
public static int getNumberOfObjects() {return SportEvent.getEventList().size();} // static method, cannot be over-ridden
@Override // project2.Game.getWinner()
public String getWinner() {return this.getTeams()[this.getWinnerIndex()];} // getWinner()
@Override // project2.Game.getLoser()
public String getLoser() {return this.getTeams()[this.getLoserIndex ()];}
@Override // project2.Game.getWinnerScore()
public int getWinnerScore() {return this.getScores()[this.getWinnerIndex()];} // getWinner()
@Override // project2.Game.getLoserScore()
public int getLoserScore() {return this.getScores()[this.getLoserIndex()];}
@Override // chapter13.Event.toString()
public String toString() {return super.toString() + " [teams = " + this.getTeams()[0] + " vs " + this.getTeams()[1] + ", scores = " + this.getScores()[0] + " - " + this.getScores()[1] + ", " + this.getWinner() + " won, league = " + this.getLeague() + "]";}
} // class SportEvent