Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

? Problem Statement his question aims to test your knowledge of java.lang, java.util, ind java.time package in Java. As a Java developer, we know that

image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed?
Problem Statement his question aims to test your knowledge of java.lang, java.util, ind java.time package in Java. As a Java developer, we know that TreeSet uses a tree-based data structure for storing elements and the elements are arranged in their natural ordering. So, the TreeSet always depends on the compareTo0 method of Comparable interface for ordering as well as for detecting the duplicates. The Comparable interface is present inside java.lang package. So, based on the concepts of TreeSet and compareTo() method of Comparable T> interface, implement as per the given requirement. Requirement: The partially implemented Player class is provided for you in your editor. It has 3 fields: playerName, average, and playerDOB. The respective getters and setters are given for these instance variables and the tostring 0 method from the Object class is already overridden as per the requirement. Logic is given to read a list of Player objects in the InfycupCricketSelection class. Write the logic that will return a Map containing the batting order based on the best average. Irite the logic that will return a Map containing the batting order ased on the best average. f two players having the same average then the batting order will pe decided based on their age, i.e. the elder one gets the priority. If two players having the same average as well as their age are the same then batting order will be decided based on their names, i.e. natural ordering of the names. Input Format: Input from stdin using Scanner is handled in a fully implemented InfyCupCricketSelection class. The first line contains an int value, denoting the number of players. Subsequent lines contain Player object details. Example: 5 Smith 40.62/06/1988 Warner 50.227/10/1986 Finch 46.717/11/1986 Lyon 20.720/11/1987 ructions: mplete the Player class as given below: The Player class should implement the Comparable interface and override the compareTo(Object o) method so that: (When the user-defined Player class will be added into a TreeSet, implicitly this compareTo() method will be get called to decide the ordering as well as finditgg the duplicates) a. They must be arranged according to their average, i.e. The Player having higher average must get the priority and will come first in the batting order. b. If two Players having the same average then they must be arranged according to their age, i.e. The Player who is elder must get the priority(Please note that the datatype of the playerDOB is given in String format, So while comparing the ages convert it into java.time.LocaDate). c. Again, if two Players having the same average as well as of the same age then they must be arranged according to their name, i.e. The Player names in natural ordering. 2. Complete the selectionProcess(List playerList, int noOfPlayers) as below: a. Create a local variable 'playerSet, which is a TreeSet and store all the Player objects from playerList, based on the logic provided by overriding the compareTo0 method in the previous step. b. Finally create another local variable 'finalBattingOrder', logic provided by overriding the compareTo0 method in the previous step. b. Finally create another local variable 'finalBattingOrder. which is HashMap. The key and value pair for this HashMap should be ': By using the variable 'noOfPlayers' copy all the elements from 'playerSet' and put them into the 'finalBattingOrder. The batting order should start from 1 instead of 0 . Refer to the sample input and output section for more clarification. For example, if the input is : ith 40.62/06/1988 arner 50.227/10/1986 ch 46.717/11/1986 on 20.720/11/1987 axwell 50.214/11/1985 hen the output will be: {1= Maxwell, 2= Warner, 3= Finch, 4=5mith, - Please don't alter/change the code provided. - Whatever class/interface you are adding OR already provided should not be 'public'. age. In this example, Marry is older than Jack based on the DOB provided. So, Marry gets priority over Jack after Sherlock and John respectively. 4 Jack 40.612/06/1993 Sherlock 50.7 28/12/1994 John 45.829/01/1995 Marry 40.612/06/1993 {1= Sherlock, 2=John, Here Sherlock and John 3= Jack, 4= Marry have higher averages than Jack and Marry. As the average and the ager of Jack and Marry are the same then the batting order will be decided based on their natural ordering of names. In this example, J comes before M. So, Jack gets priority over Marry after Sherlock and John respectively. class playen \{ private String playerName; private Double avarage; private String playerDOB; public Player (String playerName, Double avarage, String playerDOB) super () ; this. playerName = playerName; this . avarage = avarage; this.playerDOB = playerDOB; 3 public string getPlayerName() \{ return playerName; 3 public void setPlayerName(String playerName) \{ this. playerName = playerName; public string tostring() \{ return this.playerName +; 3 public static Map> playerlist, int noofplayers) /Nrite your logic as per the instructions return null

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

What is the basis for Security Concerns in Cloud Computing?

Answered: 1 week ago

Question

Describe the three main Cloud Computing Environments.

Answered: 1 week ago