?
package pl.codegym.task.task08.task0803;
import java.util.HashMap;
import java.util.Map;
/*
HashMap kotów
*/
public class Solution {
public static void main(String[] args) throws Exception {
String[] koty = new String[]{"Tygrysek", "Mania", "Odlot", "Marmolada", "Oskar", "Śnieżek", "Szefu", "Kafel", "Max", "Simba"};
HashMap<String, Kot> mapa = dodajKotyDoMap(koty);
for (Map.Entry<String, Kot> para : mapa.entrySet()) {
System.out.println(para.getKey() + " - " + para.getValue());
}
}
public static HashMap<String, Kot> dodajKotyDoMap(String[] koty) {
//tutaj wpisz swój kod
HashMap<String, Kot> mapa = new HashMap<String, Kot>();
Kot kot1 = new Kot("Tygrysek");
Kot kot2 = new Kot("Mania");
Kot kot3 = new Kot("Odlot");
Kot kot4 = new Kot("Marmolada");
Kot kot5 = new Kot("Oskar");
Kot kot6 = new Kot("Śnieżek");
Kot kot7 = new Kot("Szefu");
Kot kot8 = new Kot("Kafel");
Kot kot9 = new Kot("Max");
Kot kot10 = new Kot("Simba");
mapa.put(koty[0],kot1 );
mapa.put(koty[1],kot2 );
mapa.put(koty[2],kot3 );
mapa.put(koty[3],kot4 );
mapa.put(koty[4],kot5 );
mapa.put(koty[5],kot6 );
mapa.put(koty[6],kot7 );
mapa.put(koty[7],kot8 );
mapa.put(koty[8],kot9 );
mapa.put(koty[9],kot10 );
return mapa;
}
public static class Kot {
String imie;
public Kot(String imie) {
this.imie = imie;
}
@Override
public String toString() {
return imie != null ? imie.toUpperCase() : null;
}
}
}