Hello, it does work.
but it won't pass the test becase the output is in a different order, like this:
Snowball - SNOWBALL
Boss - BOSS
Missy - MISSY
Simba - SIMBA
Max - MAX
Smokey - SMOKEY
Tiger - TIGER
Marmalade - MARMALADE
Oscar - OSCAR
Smudge - SMUDGE
does anybody know why?
thanks
package com.codegym.task.task08.task0803;
import java.util.HashMap;
import java.util.Map;
/*
HashMap of cats
*/
public class Solution {
public static void main(String[] args) throws Exception {
String[] cats = new String[]{"Tiger", "Missy", "Smokey", "Marmalade", "Oscar", "Snowball", "Boss", "Smudge", "Max", "Simba"};
HashMap<String, Cat> map = addCatsToMap(cats);
for (Map.Entry<String, Cat> pair : map.entrySet()) {
System.out.println(pair.getKey() + " - " + pair.getValue());
}
}
public static HashMap<String, Cat> addCatsToMap(String[] cats) {
HashMap<String, Cat> map1 = new HashMap<String, Cat>();
for ( int i = 0; i<10 ; i++){
Cat cat = new Cat(cats[i]);
map1.put(cats[i], cat);
}
return map1;
}
public static class Cat {
String name;
public Cat(String name) {
this.name = name;
}
@Override
public String toString() {
return name != null ? name.toUpperCase() : null;
}
}
}