Main.java x 1 import java.util.*; 2 3 4 v 5 V 6 class Main { www...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
Main.java x 1 import java.util.*; 2 3 4 v 5 V 6 class Main { www public static void main(String[] args) { /* Code for testing HashMap hash_map = new HashMap (); hash_map.put(1, "John"); 7 8 hash_map.put(2, "Doe"); 9 hash_map.put(3, "James"); 10 11 12 13 hash_map.put(4, "Eric"); System.out.println(even (hash_map)); HashMap hash_map2 = new HashMap () 14 hash_map2.put(1, 30); 15 hash_map2.put(2, 40); 16 hash_map2.put(3, 50); 17 18 19 hash_map2.put(4, 60); System.out.println(average (hash_map2)); */ 20 } 21 22 //add your code here.... 23 24 25 } Hashing (50 points) a. Write a method that creates a list of all the values in a HashMap that are located at even keys. You will then sort that list (using Collections.sort) and return the sorted list. Call this method: even O Parameter(s): HashMap Returns: ArrayList O Given the map: {1: "a", 2: "x", 3: "c", 4: "d"}, the result should be list {"d", "X"} b. Write a method that gets the average of all the values in the HashMap. Call this method: average O Parameter(s): HashMap Returns: a double Given the map: {1:10, 2:20, 5:30, 7:40}, the result should be 25 Main.java x 1 import java.util.*; 2 3 4 v 5 V 6 class Main { www public static void main(String[] args) { /* Code for testing HashMap hash_map = new HashMap (); hash_map.put(1, "John"); 7 8 hash_map.put(2, "Doe"); 9 hash_map.put(3, "James"); 10 11 12 13 hash_map.put(4, "Eric"); System.out.println(even (hash_map)); HashMap hash_map2 = new HashMap () 14 hash_map2.put(1, 30); 15 hash_map2.put(2, 40); 16 hash_map2.put(3, 50); 17 18 19 hash_map2.put(4, 60); System.out.println(average (hash_map2)); */ 20 } 21 22 //add your code here.... 23 24 25 } Hashing (50 points) a. Write a method that creates a list of all the values in a HashMap that are located at even keys. You will then sort that list (using Collections.sort) and return the sorted list. Call this method: even O Parameter(s): HashMap Returns: ArrayList O Given the map: {1: "a", 2: "x", 3: "c", 4: "d"}, the result should be list {"d", "X"} b. Write a method that gets the average of all the values in the HashMap. Call this method: average O Parameter(s): HashMap Returns: a double Given the map: {1:10, 2:20, 5:30, 7:40}, the result should be 25
Expert Answer:
Related Book For
Java How To Program Late Objects Version
ISBN: 9780136123712
8th Edition
Authors: Paul Deitel, Deitel & Associates
Posted Date:
Students also viewed these programming questions
-
A random sample of 100 high school students was taken and the following table gives a summary of their responses when they were asked what their favorite season is. We are interested in testing to...
-
Carol Harris, Ph.D, CPA, is a single taxpayer and she lives at 674 Yankee Street, Durham, NC 27409. Her Social Security number is 793-52-4335. Carol is an Associate Professor of Accounting at a local...
-
In the context of supply and demand under international trade, when will a country decide to export a particular good? Import a good? Who gains and loses under each decision?
-
The DellaVecchia Garden Center purchases and sells Christmas trees during the holiday season. It purchases the trees for $10 each and sells them for $20 each. Any trees not sold by Christmas day are...
-
InnoTech Applications paid $1,300,000 in research costs for a new software program. InnoTech also paid $1,000,000 to acquire a patent on other software. After readying the software for production,...
-
Assume the following exceptions to prescribed control procedures over cash receipts transactions occurred in the Janz Company: 1. A mail remittance was misappropriated after receipt. 2. A cash sale...
-
Given the data in Problem 7, determine the first activities to be crashed by the following priority rules: (a) Shortest task first. (b) Most resources first (use normal cost as the basis). (c)...
-
(I) (a) The two protons in the H molecule are 0.74 10-10 m apart. What is the electrostatic force between them? (b) In a NaCl crystal, the Na+ and Cl ions are 2.82 x 10-10 m apart. What is the force...
-
10.3 An EM wave in free space is described by H = 0.4 cos(10t + By) A/M %3D Determine (a) the angular frequency w, (b) the wave number B, (c) the wavelengur (d) the direction of wave propagation, (e)...
-
IRAC answer to the question I was received about whether sam is criminally liable for assault for his actions against basil. Is this a good answer so far or is there anything I could change/doesnt...
-
The spot rate is 110 per dollar. Assume that speculator buys 10,000 today and invests the amount in a yen denominated bond. The interest rate earned is 1%. One year later the spot rate turns out to...
-
On April 1, 2022, an investor bought 2500 shares of PT Telkom Tbk. With a price of IDR 4550 per share. The investor gets a margin of 65% with a maintenance margin of 30%. Try to determine what the...
-
Miller Company's contribution format income statement for the most recent month is shown below: Total Sales (25,200 units) Variable expenses $ 226,800 136,080 Contribution margin 90,720 Per Unit $...
-
$1 million to be paid in exactly one year, plus 10 years of monthly payments of $5,000, with the first of the monthly payments to be made exactly 18 months from now. If the discount rate embedded in...
-
Strict Liability vs Negligence are both causes of action under tort law Please provide a short answer on the differences between strict liability and negligence and include an example of each of...
-
The cash records of Holly Company show the following four situations. 1. The June 30 bank reconciliation indicated that deposits in transit total $720. During July, the general ledger account Cash...
-
What is the difference between the following pairs? a) Deadlockstarvation b) Waitsleep c) Concurrencyparallelism d) Readyrunnable e) NotifynotifyAll f) Waiting statetimed waiting state g) blockeddead.
-
Create a Contacts app modeled after the Cover Viewer app. Store the contact information in an ObservableList of Contact objects. A Contact should contain first name, last name, email and phone number...
-
Write a method isDivisible that uses the remainder operator (%) to determine whether ten input integers are divisible by 5 or not. The method should take an integer argument and return true if the...
-
On 1 January 2024, a company receives gross debenture interest of 1,600 from another UK company and pays net debenture interest of 8,640 to individuals. Explain the corporation tax treatment of each...
-
Visit Transparency Internationals website and check to see how the CPI Index for countries listed in Exhibits 5.4 and 5.6 has changed. After searching TIs databank, explain why the changes have...
-
Identify the accounting periods relating to the following periods of account: (a) year to 30 November 2023 (b) 1 October 2022 to 31 July 2023 (c) 1 January 2024 to 31 January 2024 (d) 33 months to 31...
Study smarter with the SolutionInn App