Java Java Maps Java Maps Java Maps Quiz

Rob Siepkowski
Rob Siepkowski
7,641 Points

Java "get" method on a Map. Question from Quiz

/*** This is a quiz question. It is asking us to fill in blank below to retrieve Ravi's grade. I have tried a dozen different variations of studentGradeMap.get() with random spellings and variations of ravi and student and quotes and parens and everything I can think of and nothing is working. please help!! Thank you! ***/

Fill in the blank to retrieve Ravi's Grade from the Map:

import java.util.HashMap; import java.util.Map;

public class Main {

public static void main(String[] args) {
    Student ravi = new Student();
    Student sid = new Student();
    Student grace = new Student();
    Grade A = new Grade();
    Grade B = new Grade();
    Grade C = new Grade();
    Grade D = new Grade();

    Map<Student, Grade> studentGradeMap = new HashMap<>();
    studentGradeMap.put(ravi, B);
    studentGradeMap.put(sid, C);
    studentGradeMap.put(grace, B);

    Grade ravisGrade = // ????? fill in blank here ??????


class Student { // omitted }

class Grade { // omitted }

3 Answers

Rob Siepkowski
Rob Siepkowski
7,641 Points

Thanks Kris! Much appreciated!!

I thought I had already tried that.

I had tried the exact same thing you wrote, but I was putting ravi in quotes ... "ravi". That's where i was going wrong.

Your answer works perfectly!

Thanks so much!

Hi there.I was facing the same issue but you already asked the same question thank you so much.