Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1. Create a package named, “prob3” and a class named, “Games2”. 2. Create a Play

ID: 3693405 • Letter: 1

Question

1. Create a package named, “prob3” and a class named, “Games2”.
2. Create a Player class and add this code:
public class Player {
private String name;
private int points;
public Player(String name, int points) {
this.name = name;
this.points = points;
}
public String getName() {
return name;
}
public int getPoints() {
return points;
}
@Override
public String toString() {
return "name=" + name + ", points=" + points;
}
}


3. Define a TreeSet in main to hold Player objects sorted by name, then points. Test with this code:
Player p1 = new Player("Benito", 33);
Player p2 = new Player("Quincy", 14);
Player p3 = new Player("Lean", 22);
Player p4 = new Player("Carly", 41);
Player p5 = new Player("Pepper", 18);
3
// Add your code to define TreeSet named "team" here
team.addAll(Arrays.asList(p1,p2,p3,p4,p5));
System.out.println(" Players sorted by name:");
for(Player p : team) System.out.println(p);
Hint: You need to implement and use a Comparator, NameComparator, to sort players by name, then points, in a TreeSet


4. Write a method named getPlayersAbove that accepts a TreeSet of Player objects and an integer, val. The method should return a set of Players containing only the players with points at or above val.


Hints:
(1) You need to implement and use a Comparator, PointsComparator, to sort players by points, then name, in a TreeSet
(2) Create a “dummy” player with points val and use the method tailSet on TreeSet to return a set of all players that are larger than or equal to the “dummy” player in terms of points.


5. Add the code below to the bottom of main to test:
Set<Player> big = getPlayersAbove(team,20);
System.out.println(" Players with a lot of points:");
for(Player p : big) System.out.println(p);


The excepted outcome is as follows:
Players sorted by name: name=Benito, points=33 name=Carly, points=41 name=Lean, points=22 name=Pepper, points=18 name=Quincy, points=14
Players sorted by points: name=Quincy, points=14 name=Pepper, points=18 name=Lean, points=22 name=Benito, points=33 name=Carly, points=41
Players with a lot of points: name=Lean, points=22 name=Benito, points=33 name=Carly, points=41

Explanation / Answer

Board.java

Spot.java

Piece.java

King.java

Knight.java

Bishop.java