Problems with Hashmap

With Java in introduction to HashMap it wants me to put in the code “HashMap<String, Integer> restaurantMenu = new HashMap<String, Integer>();” inside the main. But when I ht run I get this message:

TemperaturesForEach.java:15: error: cannot find symbol
HashMap<String, Integer> restaurantMenu = new HashMap<String, Integer>();
^
symbol: class HashMap
location: class TemperaturesForEach
TemperaturesForEach.java:15: error: cannot find symbol
HashMap<String, Integer> restaurantMenu = new HashMap<String, Integer>();
^
symbol: class HashMap
location: class TemperaturesForEach
2 errors

This is what my code looks like.

import java.util.ArrayList;

public class TemperaturesForEach {
public static void main(String args) {

    ArrayList<Integer> weeklyTemperatures = new ArrayList<Integer>();
    weeklyTemperatures.add(78);
    weeklyTemperatures.add(67);
    weeklyTemperatures.add(89); 
    weeklyTemperatures.add(94);
    
    for (Integer temperature : weeklyTemperatures) {
        System.out.println(temperature);
    }
HashMap<String, Integer> restaurantMenu = new HashMap<String, Integer>();

}

}

Please post a link to the exercise page. Thanks.

https://www.codecademy.com/courses/learn-java/lessons/data-structures/exercises/hashmap

Think this is it.

I am having this problem too.
import java.util.ArrayList;
import java.util.HashMap;
public class TemperaturesForEach {
public static void main(String args) {
HashMap<String,Integer> restaurantMenu = new HashMap<String,Integer>();
ArrayList weeklyTemperatures = new ArrayList();
weeklyTemperatures.add(78);
weeklyTemperatures.add(67);
weeklyTemperatures.add(89);
weeklyTemperatures.add(94);

    for (Integer temperature : weeklyTemperatures) {
        System.out.println(temperature);
    }

}

}

Error: Did you create the restaurantMenu HashMap inside of main?

Just so we’re clear, is this the lesson with the restaurant.java tab (Lesson 9)?

Why are you guys including weeklyTemperatures in the restaurantMenu exercise?

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.