undefined

Practice using Set and Map

Java Syntax
Level 8 , Lesson 8
Available

"I trust you've already learned about Set and Map. Here are some tasks to help reinforce your new knowledge."

undefined
2
Task
Java Syntax, level 8, lesson 8
Locked
20 words that start with the letter "L"
Do you have a favorite letter? Well, your preferences play no role in this task. Your teacher (the one who came up with this task) favors the letter "L", so you'll have to work with it, whether you like it or not. You need to create a Set and add 20 words that start with the letter "L". And, well, that's it.
undefined
10
Task
Java Syntax, level 8, lesson 8
Locked
Greater than 10? You're not a good fit for us
The Oddiozo transshipment center is looking for employees. The only requirement is this: employees must not have more than ten limbs (we don't know where this form of discrimination came from). We'll help them with a program that will create a set of numbers (Set ), add 20 different numbers, and then remove from the set all the numbers greater than 10.
undefined
10
Task
Java Syntax, level 8, lesson 8
Locked
Census
People and other citizens of the universe quite often try to find their relatives. Let's take a step towards a program that can search for people. In this task, we need to create a dictionary (Map), add ten (last name, first name) entries, and then check how many people have the same first name or last name.
undefined
10
Task
Java Syntax, level 8, lesson 8
Locked
Kind Emma and the summer holidays
Emma Richards is the supervising teacher of grade 7B at some Terran school. The details aren't important. What is important is that she gives gifts to the students on their birthdays. But not everyone is lucky: Summer birthdays are skipped due to the summer break. Let's write a program for Emma: create a dictionary with names and birth dates, and then remove anybody born in the summer.
undefined
10
Task
Java Syntax, level 8, lesson 8
Locked
We don't need repeats
It's difficult to imagine a situation where you might need the program we're going to ask you to write. However, small modifications can make it practical. You can also imagine it as part of something larger, such as a search engine. Let's create a dictionary, fill it with (last name, first name) entries, and then remove people with the same first name.
undefined
5
Task
Java Syntax, level 8, lesson 8
Locked
Only for the rich
Our customer is the Monte Vegas Casino on Planet Diabloblo. Extremely arrogant guys, but they pay well. They've asked us to make an automatic mailing list for potential customers. Don't worry. The junior programmer (you) has been assigned a simple task: create a (last name, salary) dictionary and remove any entries for people whose salary is less than 500 credits.
Comments (50)
TO VIEW ALL COMMENTS OR TO MAKE A COMMENT,
GO TO FULL VERSION
ImDevin Level 9 Old Town United States
1 May 2021
the Hard tasks were really hard, but looked up a lot and learned a ton. I guess CG is trying to force us to learn like the programmers on the job? Even so, a little more instructions would've been better. Most difficulty was getting used to the multiple ways to iterate through the data structures and getting familiar with the details of the each methods. It was super helpful to read others' questions and those who commented/answered them. So, thanx everybody and happy coding! :)
John H Level 12 Charlotte United States
11 April 2021
For "We don't need repeats", pay close attention to what is required! You must remove ALL people with the same first names. My downfall was that I was trying to keep the first person and remove the remaining ones with the same name. Wasted a lot of time on this one. Hope this helps someone.
Sinisa Level 11 Banja Luka Bosnia and Herzegovina
9 March 2021
Boy what a complication for those data structures in comparison to Python.
Sinisa Level 11 Banja Luka Bosnia and Herzegovina
9 March 2021
The tasks are not so hard, but poorly explained. If the problem is unclear or badly explained you can't develop a solution to it. I find myself increasingly wasting time with confusion stemming from very bad task requirements, instead of thinking about the algorithms to actually solve the particular issues.
ugabuga Level 14 Lund Sweden
7 March 2021
Why do I need to create a new HashMap with parameter first HashMap inside the methods to remove? For example in "Only for the rich":

public static void removeItemFromMap(HashMap<String, Integer> map) {
        HashMap<String, Integer> copy = new HashMap<>(map);
        for (Map.Entry<String, Integer> salary : copy.entrySet()){
            if (salary.getValue() < 500)
                map.remove(salary.getKey());
        }

    }
Why can't I just use the original map? Can you please explain why this is how it's done.
Guanting Liu Level 13 Springfield United States
11 November 2020
don't use set.remove because set.remove which is a boolean type method,try to use iterator
Eefke Burg Level 8 Utrecht Netherlands
8 November 2020
😂 Well the hard exercises were hard all right...
Karas Level 19 Tampa United States
27 September 2020
A comment on the sequence of these exercises: They are HARD for a reason. But they are very well worth the 10 points each.
Mariam Level 9 Columbus United States
14 September 2020
"20 words that start with the letter "L"" DIFFERENT words. The authors should clearyfy that they want us to provide DIFFERENT not the same words
bob Level 8 Milan Italy
28 June 2020
the link below might as well be required reading. this will prove to be a great help for many of you struggling through some of this material. there are also other links and references on the page worth exploring for further explanation of some related topics covered in this section of codegym. really explained well and clearly with examples. looking forward to exploring this site a bit further. https://javarevisited.blogspot.com/2017/08/how-to-remove-key-value-pair-from-map-iteration-java-example.html