package de.codegym.task.task08.task0803;
import java.util.HashMap;
import java.util.Map;
/*
HashMap für Katzen
*/
public class Solution {
public static void main(String[] args) throws Exception {
String[] katzen = new String[]{"Tiger", "Missy", "Smokey", "Marmalade", "Oscar", "Snowball", "Boss", "Mailo", "Max", "Simba"};
HashMap<String, Katze> map = katzenZurMapHinzufügen(katzen);
for (Map.Entry<String, Katze> paar : map.entrySet()) {
System.out.println(paar.getKey() + " - " + paar.getValue());
}
}
public static HashMap<String, Katze> katzenZurMapHinzufügen(String[] cats) {
HashMap<String, Katze> map = new HashMap<>();
for(String cat : cats){
map.put(cat, new Katze(cat));
}
return map;
}
public static class Katze {
String name;
public Katze(String name) {
this.name = name;
}
@Override
public String toString() {
return name != null ? name.toUpperCase() : null;
}
}
}
Last requirement not met - why?What is wrong with the output
Gelöst
Kommentare (2)
- Beliebt
- Neu
- Alt
Du musst angemeldet sein, um einen Kommentar schreiben zu können
Artem Divertitto Senior Android Developer bei United Tech
17 März 2020, 07:42
Change Mailo with Smudge
0
Ivan
16 März 2020, 16:32
The issue is not with your printing, but with the adding method 'katzenZurMapHinzufügen'.
My suggestion is to use utilize for loop and have in the loop a String which will take the 'i' as a key, then just add it like you did with your for-each
0