-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
62 lines (44 loc) · 2.12 KB
/
Copy pathMain.java
File metadata and controls
62 lines (44 loc) · 2.12 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
package Generics.FirstExample;
import java.util.ArrayList;
import java.util.Collections;
public class Main {
public static void main(String[] args) {
FootballPlayer joe = new FootballPlayer("Joe");
BaseballPlayer pat = new BaseballPlayer("Pat");
SoccerPlayer seif = new SoccerPlayer("Seif");
// Team Object for Football players using generics:
Team<FootballPlayer> jets = new Team<>("Rich Block USA");
jets.addPlayer(joe);
//Now this doesn't work anymore because the compiler is reading that pat and joe don't meet the criteria
//jets.addPlayer(pat);
//jets.addPlayer(seif);
//Render object:
System.out.println(jets.numPlayers());
Team<BaseballPlayer> baseballTeam = new Team<>("Yankees");
baseballTeam.addPlayer(pat);
Team<SoccerPlayer> brokenTeam = new Team<>("this won't work");
brokenTeam.addPlayer(seif);
Team<FootballPlayer> melbourne = new Team<>("Melbourne");
FootballPlayer banks = new FootballPlayer("Gordon");
melbourne.addPlayer(banks);
Team<FootballPlayer> hawthorn= new Team<>("Hawthorn");
Team<FootballPlayer> fremantle= new Team<>("Fremantle");
hawthorn.matchResult(fremantle, 1, 0);
hawthorn.matchResult(jets, 3, 8);
jets.matchResult(fremantle, 2, 1);
jets.matchResult(hawthorn, 1, 1);
System.out.println("Rankings");
System.out.println(jets.getName() + ": " + jets.ranking());
System.out.println(melbourne.getName() + ": " + melbourne.ranking());
System.out.println(fremantle.getName() + ": " + fremantle.ranking());
System.out.println(hawthorn.getName() + ": " + hawthorn.ranking());
//Testing out comparisons:
System.out.println(jets.compareTo(melbourne));
System.out.println(jets.compareTo(hawthorn));
System.out.println(hawthorn.compareTo(jets));
System.out.println(melbourne.compareTo(fremantle));
//Sort the list by using the static Sort method of the Collections class
// ArrayList<Team> teams;
// Collections.sort(teams);
}
}