Question: Can you please Modify the ProductSales program using (1) HashMap and (2) LinkedHashMap. Measure the efficiency of three different programs using TreeMap, HashMap, and LinedHashMap.

Can you please Modify the ProductSales program using (1) HashMap and (2) LinkedHashMap. Measure the efficiency of three different programs using TreeMap, HashMap, and LinedHashMap. Which implementation is most efficient?

import java.io.File; import java.io.IOException; import java.util.Scanner; import java.util.TreeMap;

/** * Demonstrates the use of a TreeMap to store a sorted group of Product * objects. * * @author Java Foundations * @version 4.0 */ public class ProductSales { /** * Processes product sales data and prints a summary sorted by * product code. */ public static void main(String[] args) throws IOException { TreeMap sales = new TreeMap();

Scanner scan = new Scanner(new File("salesData.txt"));

String code; Product product; while (scan.hasNext()) { code = scan.nextLine(); product = sales.get(code); if (product == null) sales.put(code, new Product(code)); else product.incrementSales(); }

System.out.println("Products sold this period:"); for (Product prod : sales.values()) System.out.println(prod); } }

Thanks

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!