package fr.codegym.task.task09.task0927;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
/*
Dix chats
*/
public class Solution {
public static void main(String[] args) {
Map<String, Chat> map = creerMap();
Set<Chat> ensemble = convertirMapEnSet(map);
imprimerSetChats(ensemble);
}
public static Map<String, Chat> creerMap() {
HashMap<String, Chat> map = new HashMap<>(10);
map.put("Simba", new Chat("Simba"));
map.put("Tom", new Chat("Tom"));
map.put("Arbus", new Chat("Arbus"));
map.put("Laurandin", new Chat("Laurandin"));
map.put("Aldo", new Chat("Aldo"));
map.put("Krypto", new Chat("Krypto"));
map.put("Grimaldo", new Chat("Grimaldo"));
map.put("Harry", new Chat("Harry"));
map.put("Gervey", new Chat("Gervey"));
map.put("Berto", new Chat("Berto"));
return map;
}
public static Set<Chat> convertirMapEnSet(Map<String, Chat> map) {
//écris ton code ici
HashSet<Chat> ensemble = new HashSet<>(10);
ensemble.add(new Chat("Simba"));
ensemble.add(new Chat("Tom"));
ensemble.add(new Chat("Arbus"));
ensemble.add(new Chat("Laurandin"));
ensemble.add(new Chat("Aldo"));
ensemble.add(new Chat("Krypto"));
ensemble.add(new Chat("Grimaldo"));
ensemble.add(new Chat("Harry"));
ensemble.add(new Chat("Gervey"));
ensemble.add(new Chat("Berto"));
return ensemble;
}
public static void imprimerSetChats(Set<Chat> ensemble) {
for (Chat chat : ensemble) {
System.out.println(chat);
}
}
public static class Chat {
private String nom;
public Chat(String nom) {
this.nom = nom;
}
public String toString() {
return "Chat " + this.nom;
}
}
}