Question

Answer in eclispe please!!! Do the following: 1. Create a package named, “prob3” and a class...

Answer in eclispe please!!!

Do the following:

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);

// Add your code to define TreeSet named "team" here

team.addAll(Arrays.asList(p1,p2,p3,p4,p5));

System.out.println("\nPlayers 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 big = getPlayersAbove(team,20);

System.out.println("\nPlayers 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

0 0
Add a comment Improve this question Transcribed image text
Request Professional Answer

Request Answer!

We need at least 10 more requests to produce the answer.

0 / 10 have requested this problem solution

The more requests, the faster the answer.

Request! (Login Required)


All students who have requested the answer will be notified once they are available.
Know the answer?
Add Answer to:
Answer in eclispe please!!! Do the following: 1. Create a package named, “prob3” and a class...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Similar Homework Help Questions
  • Java -Create an interface and implement it In the murach.db package, create an interface named IProductDB....

    Java -Create an interface and implement it In the murach.db package, create an interface named IProductDB. This interface should specify this abstract method: public abstract Product get(String productCode); Modify the ProductDB class so it implements the IProductDB interface. Write the code for the new ‘get’ method. Then remove the getProductByCode method. In the Main class, modify the code so it works with the new ProductDB class. This code should create an instance of the IProductDB interface like this: IProductDB db...

  • Modify the program that you wrote for the last exercise in a file named Baseball9.java that...

    Modify the program that you wrote for the last exercise in a file named Baseball9.java that uses the Player class stored within an array. The program should read data from the file baseball.txt for input. The Player class should once again be stored in a file named Player.java, however Baseball9.java is the only file that you need to modify for this assignment. Once all of the input data from the file is stored in the array, code and invoke a...

  • Problem 1 1. In the src → edu.neiu.p2 directory, create a package named problem1. 2. Create...

    Problem 1 1. In the src → edu.neiu.p2 directory, create a package named problem1. 2. Create a Java class named StringParser with the following: • A public static method named findInteger that takes a String and two char variables as parameters (in that order) and does not return anything. • The method should find and print the integer value that is located in between the two characters. You can assume that the second char parameter will always follow the first...

  • This java assignment will give you practice with classes, methods, and arrays. Part 1: Player Class...

    This java assignment will give you practice with classes, methods, and arrays. Part 1: Player Class Write a class named Player that stores a player’s name and the player’s high score. A player is described by:  player’s name  player’s high score In your class, include:  instance data variables  two constructors  getters and setters  include appropriate value checks when applicable  a toString method Part 2: PlayersList Class Write a class that manages a list...

  • Create a class named Circle with fields named radius, diameter, and area. Include a constructor that...

    Create a class named Circle with fields named radius, diameter, and area. Include a constructor that sets the radius to 1 and calculates the other two values. Also include methods named setRadius() and getRadius(). The setRadius() method not only sets the radius, but it also calculates the other two values. (The diameter of a circle is twice the radius, and the area of a circle is pi multiplied by the square of the radius. Use the Math class PI constant...

  • Please help me do the java project For this project you will be reading in a...

    Please help me do the java project For this project you will be reading in a text file and evaluating it in order to create a new file that represents the Class that will represent the properties of the text file. For example, consider the following text file: students.txt ID              Name                              Age                    IsMale           GPA 1                Tom Ryan                       22                       True              3.1 2                Jack Peterson                31                       True              2.7 3                Cindy LuWho                12                       False             3.9 When you read in the header line, you...

  • FOR JAVA: Summary: Create a program that adds students to the class list (see below). The...

    FOR JAVA: Summary: Create a program that adds students to the class list (see below). The solution should be named Roster402_v2.java. Allow the user to control the number of students added to the roster. Ask if the user would like to see their new roster to confirm additions. If yes, then display contents of the file, if no, end the program. ------------------------------------------------------------------------------------- List of student names and IDs for class (this will be your separate text file): Jones, Jim,45 Hicks,...

  • ***Code to solve*** package functions; import java.math.*; // for BigInteger public class NodeTransitionFunction {    public...

    ***Code to solve*** package functions; import java.math.*; // for BigInteger public class NodeTransitionFunction {    public NodeTransitionFunction(Integer exp, Integer KVal) {        // CONSTUCTOR: Sets the class to calculate f(x) = (x ^ exp) mod KVal        // TODO    }             public Integer apply(Integer val) {        // PRE: -        // POST: Implements f(val)        return null;    }       public BigInteger apply(BigInteger val) {        // PRE:...

  • Read through the code of the class Player, noting it has two instance variables, name and rank, which are of type String and three further instance variables won, drew and lost which are of type int....

    Read through the code of the class Player, noting it has two instance variables, name and rank, which are of type String and three further instance variables won, drew and lost which are of type int. There is also an attribute of the class, points, which does not have a corresponding instance variable. Also note the constructor and methods of the class and what they do. TournamentAdmin class code: public class RankAdmin {    /**     * Constructor for objects of class...

  • 1. Do the following a. Write a class Student that has the following attributes: - name:...

    1. Do the following a. Write a class Student that has the following attributes: - name: String, the student's name ("Last, First" format) - enrollment date (a Date object) The Student class provides a constructor that saves the student's name and enrollment date. Student(String name, Date whenEnrolled) The Student class provides accessors for the name and enrollment date. Make sure the class is immutable. Be careful with that Date field -- remember what to do when sharing mutable instance variables...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT