-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTeam.java
More file actions
69 lines (57 loc) · 2.03 KB
/
Team.java
File metadata and controls
69 lines (57 loc) · 2.03 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
package gamescopy;
import java.util.*;
public class Team<T extends Player> implements Comparable<Team<T>>{/*Here Player is said to be the upper bound of T. T is a bounded parameter.*/
/*If we use any other class not derived from player as a parameter then we will get an error*/
private String teamName;
public Team(String teamName){
this.teamName = teamName;
}
public String getTeamName(){
return teamName;
}
private int lost=0;
private int win = 0;
private int played = 0;
private int tie = 0;
private List<T> member = new ArrayList<>();
public boolean addPlayer(T player){
if(member.contains(player)){
System.out.println("The player "+((Player)player).getplayerName()+" is already present in the team "+teamName);
return false;
}else{
member.add(player);
System.out.println("The player "+((Player)player).getplayerName()+" added to the team "+teamName);
return true;
}
}
public int playerNum(){
return member.size();
}
public void matchResult(Team<T> opponent, int ourScore, int theirScore){
String message = "";
if(ourScore>theirScore){
win++;
System.out.println(this.teamName+" win");
message = " wins from ";
}else if(theirScore == ourScore){
tie++;
System.out.println(this.teamName+" ties");
message = " ties ";
}else{
lost++;
System.out.println(this.teamName+" lost");
message = " lost to ";
}
played++;
if(opponent != null){
// System.out.println(this.teamName+message+opponent.getTeamName());
opponent.matchResult(null, theirScore, ourScore);
}
}
public int Ranking(){return (this.win*2)+this.tie;}
public int compareTo(Team<T> team){
if(this.Ranking() > team.Ranking()) return -1;
else if(this.Ranking() < team.Ranking()) return 1;
else return 0;
}
}