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
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
Get step-by-step solutions from verified subject matter experts
