Likes

Java Lab06_Ans1

Use the HashMap collection to Count a list of part numbers.

Solution

1 open the genrics-practices project and make the following changes.

for the productcounter class and two private map field.

private map<stirng,long> productcountmap = new hashmap<> ();
private map<string,string> product names = new treemap<> ();

create a one argument constructor thyat accepts a map as a parameter.
  public productcounter (map productnames) {
    this.productname = productnames;
}

3 create a processlist() method to process a list of string part number.
   public void processlist(string[] list) {
      long curval = 0;
   
      for(string itemnumber : list) {
          curval = productcountmap.containskey(itemnumber) ) {
            productountmap.put (itemnumber,new long(1) );
      }
         else
    {
        productcountmap.put(itemnumber,new long (curval) ) ;
 }

}

}
  

No comments: