please help i am stuck

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899603
Joined: Mon Aug 02, 2021 8:13 am

please help i am stuck

Post by answerhappygod »

please help i am stuck
Please Help I Am Stuck 1
Please Help I Am Stuck 1 (157.16 KiB) Viewed 68 times
The following code creates a Hashmap which stores name/mark pairs for the students' marks in M251. For marks analysis purposes we want to know the most common mark. Therefore it would be useful if the marks are displayed in order of how often they occurred. To meet the requirement a method printAscendingByMark is added to print out a Hashmap of strings to integers in ascending order by the integer values. The strategy of this method is to go through each of the name/mark pair and add that information to a new "reverse map" that associates each mark with a list of the students' names that had this mark. (Because there may be many students who had the same mark, the value in the reverse map needs to be a list of names). Finally, it goes through this reversed map in order by mark and produces the desired output. Complete the five missing lines as indicated in the numbered comments. public class Java Application { public static void printAscendingByMark (HashMap<String, Integer> map) // declare and create reverseMap TreeMap<Integer, ArrayList<String>> reverseMap = new TreeMap<>(); // 1. Iterate through map for (......................... ) { Integer mark = map.get(name); ArrayList<string> nameList; // 2. Check if reverseMap has an entry for the retrieved mark // get the associated list from the reverseMap • name List = reverseMap.get (mark); else // create a new namelist nameList = new ArrayList<String>(); // 3. Add the name to nameList if // 4. and stored it back in reverseMap // iterate through reverseMap and display results for (Integer mark : reverseMap.keySet()) ! // 5 Get the list associated with this mark /literate through the list and display the results for (int i = 0; i < tmpList.size(); i++) { String name = tmpList.get(i); System.out.println(name + + mark); public static void main(String[] args) { HashMap<String, Int r> nap= new HashMap<>(); map.put("Ali", 90); map.put("Rana", 85); map.put("Ramı", 90); map.put("Sami", 70): printAscendingByMark (map); }
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply