CodeGym
CodeGym University
Learning
Course
Tasks
Surveys & Quizzes
Games
Help
Schedule
Community
Users
Forum
Chat
Articles
Success stories
Activity
Reviews
Subscriptions
Light theme
Start learning now
  • All questions
Zach
Level 22
Fort Collins
  • 25.02.2021
  • 239views
  • 3comments

Don't see the problem but last task will not pass

Question about the task HashMap of Objects
Java Syntax,  Level 8,  Lesson 3
Under discussion

There is a HashMap<String, Object>. 10 different object pairs have been added to it.
Display the contents of the collection, each element on a new line.

Example output: (here we just show one line):
Sim - 5

Requirements:
  • The program must create a HashMap variable with (String, Object) elements. The variable must be initialized immediately.
  • The program should not read values from the keyboard.
  • The program should add 10 different objects to the collection in accordance with the conditions.
  • The program should display the contents of the collection on the screen, each pair on a new line.
package com.codegym.task.task08.task0806; import java.util.HashMap; import java.util.Map; /* HashMap of Objects */ public class Solution { public static void main(String[] args) throws Exception { HashMap<String, Object> map = new HashMap<String, Object>(); map.put("Sim", new Integer(5)); map.put("Tom", new Double(5.5)); map.put("Arbus", new Boolean(false)); map.put("Baby", new String("Zach")); map.put("Cat", "Cat"); map.put("Eat", new Long(56)); map.put("Food", new Character('3')); map.put("Gevey", new Character('6')); map.put("Hugs", new String("111111111111L")); map.put("Comp", new Double(123)); //write your code here for (Map.Entry<String, Object> person : map.entrySet()) { String key = person.getKey(); String value = person.getValue().toString(); System.out.println(key + " - " + value); } } }
0
Comments (3)
  • Popular
  • New
  • Old
You must be signed in to leave a comment
Guadalupe Gagnon
Level 37 , Tampa, United States
25 February 2021, 22:41
It looks like you changed a bunch of the values between lines 14-23. I would recommend resetting the task and not doing that next attempt.
0
Gellert Varga
Level 23 , Szekesfehervar, Hungary
25 February 2021, 22:13
I think the getValue() method is able to do the job, so it is able to give to You the needed value, and you don't need use the toString() method.
0
Gellert Varga
Level 23 , Szekesfehervar, Hungary
25 February 2021, 22:18
Just insert the 'person.getValue()' inside the Sys.o.print() command.
0
Learn
  • Registration
  • Java Course
  • Help with Tasks
  • Pricing
  • Game Projects
  • Java Syntax
Community
  • Users
  • Articles
  • Forum
  • Chat
  • Success Stories
  • Activity
  • Affiliate Program
Company
  • About us
  • Contacts
  • Reviews
  • Press Room
  • CodeGym for EDU
  • FAQ
  • Support
CodeGym CodeGym is an online course for learning Java programming from scratch. This course is a perfect way to master Java for beginners. It contains 1200+ tasks with instant verification and an essential scope of Java fundamentals theory. To help you succeed in education, we’ve implemented a set of motivational features: quizzes, coding projects, content about efficient learning and Java developer’s career.
Follow us
Interface language
Programmers Are Made, Not Born © 2023 CodeGym
MastercardVisa
Programmers Are Made, Not Born © 2023 CodeGym
This website uses cookies to provide you with personalized service. By using this website, you agree to our use of cookies. If you require more details, please read our Terms and Policy.