Issue
I am trying to work out how to add a value to a variable based on if a String is present in an array. Hopefully my code will explain it better:
//calculate bonus
String[] department = {"Dublin","London","London","Dublin","Paris","Paris"};
int [] brokerTotal =(79,35,55,101,63,108};
int[] bonus;
bonus=new int[6];
for(int i = 0;i < department.length; i++) {
if (department ="Dublin") bonusRate=12;
else if (department="London") bonusRate=15;
else bonusRate=10;
bonus[i] = ((brokerTotal[i])/100)*bonusRate;
}
The if statements are catching me here, am I close or totally off the mark here?
Solution
if (department="London")
should be
if ("London".equals(department))
Same goes for the if(department ="Dublin")
statement
More info:
Answered By - Konstantin Yovkov