I have this method that should return the name of the dish of a restaurant with the number of times it is in total of all restaurants. If the dish is returned 1, if it is more than once must count and return those times. but he's only giving me back 2 times and if I increase the amount he keeps counting 2. What's wrong?
class Restaurant {
String nombre;
String direccion;
int capacidad;
LinkedList<String> platosMenu;
public static HashMap<String, Integer> cuentaPlatos(LinkedList<Restaurante>
lista) {
HashMap<String, Integer> mapa = new HashMap();
ListIterator<Restaurante> it = lista.listIterator();
int cont = 1;
while (it.hasNext()) {
Restaurante clave = it.next();
LinkedList<String> platos = clave.getPlatosMenu();
for(String plato : platos){
if(mapa.containsKey(plato)){
mapa.put(plato,cont+1);
}else{
mapa.put(plato,cont);
}}}
return mapa;
Main --------------
Restaurante{nombre=Restaurante1, direccion=Sur, capacidad=50,
platosMenu=[guatita, encebollado, arroz con menestra]}
Restaurante{nombre=Restaurante2, direccion=Centro, capacidad=85,
platosMenu=[encebollado, arroz con menestra, caldo de bola]}
Restaurante{nombre=Restaurante3, direccion=Este, capacidad=100,
platosMenu=[guatita, pescado frito, encebollado, arroz con menestra]}
Retorno:
( encebollado y arroz con menestra deberian retornar 3 )
guatita - 2
encebollado - 2
caldo de bola - 1
arroz con menestra - 2
pescado frito - 1