Problems with Hashmap


#1

With Java in introduction to HashMap it wants me to put in the code "HashMap restaurantMenu = new HashMap();" inside the main. But when I ht run I get this message:

TemperaturesForEach.java:15: error: cannot find symbol
HashMap restaurantMenu = new HashMap();
^
symbol: class HashMap
location: class TemperaturesForEach
TemperaturesForEach.java:15: error: cannot find symbol
HashMap restaurantMenu = new HashMap();
^
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>();

}

}


#2

Please post a link to the exercise page. Thanks.


#3

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

Think this is it.


#4

I am having this problem too.
import java.util.ArrayList;
import java.util.HashMap;
public class TemperaturesForEach {
public static void main(String[] args) {
HashMap restaurantMenu = new HashMap();
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?


#5

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


#6

Why are you guys including weeklyTemperatures in the restaurantMenu exercise?


#7

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