-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBaseballTeam.java
More file actions
52 lines (42 loc) · 1.2 KB
/
BaseballTeam.java
File metadata and controls
52 lines (42 loc) · 1.2 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
package com.dj;
import java.util.ArrayList;
import java.util.List;
public class BaseballTeam {
private String teamName;
private List<BaseballPlayer> teamMembers = new ArrayList<>();
private int totalWins = 0;
private int totalLosses = 0;
private int totalTies = 0;
public BaseballTeam(String teamName) {
this.teamName = teamName;
}
public void addTeamMember(BaseballPlayer player) {
if (!teamMembers.contains(player)) {
teamMembers.add(player);
}
}
public void listTeamMembers() {
System.out.println(teamName + " Roster:");
System.out.println(teamMembers);
}
public int ranking() {
return (totalLosses * 2) + totalTies + 1;
}
public String setScore(int ourScore, int theirScore) {
String message = "lost to";
if (ourScore > theirScore) {
totalWins++;
message = "beat";
} else if (ourScore == theirScore) {
totalTies++;
message = "tied";
} else {
totalLosses++;
}
return message;
}
@Override
public String toString() {
return teamName + " (Ranked " + ranking() + ")";
}
}