Hello! I'm working on a homework piece and am having some issues...

I found a code snippet somewhere that shows to populate a map with an key and values corresponding to that key. It seems to work, but I don't know why or how. Is there a different way to do this?

java Code:
while (scanner.hasNext()) {
                propertyID = scanner.nextInt();
                type = scanner.next();
                price = scanner.nextDouble();
                agentID = scanner.nextInt();
                // Capitalize property type and store in the set
                // Calculate the property sales for each agent  
                if (propertyPriceMap.get(agentID) != null) {
                    totalSales = (Double) propertyPriceMap.get(agentID) + price;
                } else {
                    totalSales = price;
                propertyPriceMap.put(agentID, totalSales);

I think I get why the 'while' loop adds the property types to the set, but I don't understand how the 'while' loop adds and calculates the map property price values based on agentID and why the 'if' statement is there.

Don't get me wrong, I was happy this worked, but I would like to understand it better or know if there is a better way to populate the set and the map.

Thanks in advance!