Goals: The goals of this lab are to write methods in union data, and specifically to practice writing accumulator-style methods.
For this lab, there are no starter files. For each problem, start a new project and build the files from scratch.
One of the four grand-slam tournaments in tennis is held at Wimbledon, England. It hosts both singles and double games. In this problem, we will focus only on singles games (one player against another).
Specifically we will represent the draw of the gentleman’s singles at Wimbledon 2019. Here is a snapshot of part of this draw:
Specifically, we represent the draw using an interface named IDraw. Two classes implement this interface. The SeedPlayer class represents a single player at the bottom of the draw (where the tournament starts). A seed player has a name. The PlayResult class represents a single match. It consists of the name of the winner, and the two IDraw objects that played that match, named one and two.
For example, here is a representation of the above draw, starting from the quarter-finals:
IDraw djokovic = new SeedPlayer("Djokovic"); IDraw goffin = new SeedPlayer("Goffin"); IDraw pella = new SeedPlayer("Pella"); IDraw agut = new SeedPlayer("Agut"); ... IDraw semiFinal1 = new PlayResult("Djokovic",djokovic,goffin); IDraw semiFinal2 = new PlayResult("Agut",agut,pella); ... IDraw final1 = new PlayResult("Djokovic",semiFinal1,semiFinal2); IDraw final2 = new PlayResult("Federer",semiFinal4,semiFinal3); IDraw winner = new PlayResult("Djokovic",final1,final2);
Note that the PlayResult objects have been created so that one is always the draw from which the winner comes (e.g. final2 is constructed using semiFinal4 first because that is the draw that Federer came from.)
Define the above interface and classes, and complete the above example.
Design a method ILoString wonAgainst() that computes and returns a list of all player names that this player has won against, in the order in which they played this player. For example, winner.wonAgainst() should return a list "Goffin", "Agut", "Federer", semiFinal2.wonAgainst() should return "Pella", and goffin.wonAgainst() should return an empty list.
Design a method String nemesis(String player) that returns the name of the player who eliminated a player whose name is the argument, in this draw. If this player won the draw then it should return "Won". If there is no player with the given name, it should return "Not Found". For example winner.nemesis("Federer") should return "Djokovic", winner.nemesis("Agut") should return "Djokovic", winner.nemesis("Djokovic") should return "Won", and winner.nemesis("Murray") should return "Not Found".
Write sufficient tests for these and any helper methods you choose to write.
Do Now!After you are done with each method, think about whether you used accumulators to do it or not. Try the other way.
Do Now!The restriction that one is always the draw from which the current winner came is not really motivated. Did this restriction help you to solve these problems? Think about how to relax this restriction while still implementing the above methods correctly.