rafik
rafik

Reputation: 21

The operator * is undefined for the argument type(s) Map<String,Double>, int

How to perform division or multiplication with map without using key and values.

In below example i am having Developer as map object and want to multiply with 10 and assign it to another map.

 private Map<String, Double> Developer;

Having setter, getter method for Developer

 Map<String, Double> EmployeeVal = company.getDep().getProject().get(0).getDeveloper()*100;

if i am decalaring EmployeeVal as Double its working fine, but i dont want to do that, i want to declare EmployeeVal as Map only.

Upvotes: 0

Views: 799

Answers (1)

Vadim
Vadim

Reputation: 4120

Your problem starts with wrong naming convention.

Your Developer object is not a "developer", but a collection of Doubles with keys as String (names I guess?).

Aside of fact that it is better (and standard) to do not make variables started with capital letter your Developer variable should be named like developersMap.

Then: Do you want to multiply all values for all developers by 10?

If yes, make a loop through all of them and multiply values like:

example 1:

    for (String devKey: developersMap.keySet()){            
        developersMap.put(devKey,developersMap.get(devKey) * 10.0D);
    }

example 2:

    for (Entry<String, Double> devEntry: developersMap.entrySet()){         
        devEntry.setValue(devEntry.getValue() *10.0D);          
    }

But, if you'd like to multiply value for only one developer you have to get his value from Map by key, then multiply and put it back into Map.

As example you have two developers "John" and "Jane". for whom you'd like to multiply value?

"John":

developersMap.put("John",developersMap.get("John") * 10.0D);

Upvotes: 1

Related Questions