Count Leads by Rating with a Map
A Map<String, Integer> can keep a running count per key.
Your task
Write countByRating(List<Lead> leads) that counts Leads per Rating in a Map<String, Integer>, treating a null Rating as None, then loop over the keys and print each count.
Map<String, Integer> countByRating(List<Lead> leads) {
return null;
}
List<Lead> leads = new List<Lead>{
new Lead(LastName = 'Ito', Company = 'Acme', Rating = 'Hot'),
new Lead(LastName = 'Park', Company = 'Globex', Rating = 'Warm'),
new Lead(LastName = 'Diaz', Company = 'Initech', Rating = 'Hot'),
new Lead(LastName = 'Chen', Company = 'Umbrella')
};
Map<String, Integer> counts = countByRating(leads);Requirements
for (String key : counts.keySet())should be used to walk the MapHot: 2should be printedNone: 1should be printedcountByRatingwith two Cold Leads should be2countByRatingwithout Hot Leads should benullcountByRatingwith two Rating-less Leads should be2countByRatingwith a hidden mix should be3