package com.codegym.task.task08.task0816;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
/*
Kind Emma and the summer holidays
*/
public class Solution {
public static HashMap<String, Date> createMap() throws ParseException {
DateFormat df = new SimpleDateFormat("MMMMM d yyyy", Locale.ENGLISH);
HashMap<String, Date> map = new HashMap<String, Date>();
map.put("Stallone", df.parse("JUNE 1 1980"));
//write your code here
map.put("st", df.parse("JUNE 7 1980"));
map.put("tallone", df.parse("JULY 8 1980"));
map.put("Stllone", df.parse("AUGUST 11 1980"));
map.put("Stalone", df.parse("MEI 10 1980"));
map.put("Stallne", df.parse("SEPTEMBER 21 1980"));
map.put("Stalloe", df.parse("JANUARY 18 1980"));
map.put("Stallon", df.parse("JULY 19 1980"));
map.put("tallone", df.parse("APRIL 11 1980"));
map.put("Stall", df.parse("JUNE 19 1980"));
return map;
}
public static void removeAllSummerPeople(HashMap<String, Date> map) {
//write your code here
for(Map.Entry<String,Date> test:map.entrySet())
{Date a=test.getValue();
if(a.getMonth>5 && a.getMonth<9){map.remove(test.getKey()) ;}
}
}
public static void main(String[] args) {
// removeAllSummerPeople(createMap()) ;
}
}
help please ....I give up
Under discussion
Comments (1)
- Popular
- New
- Old
You must be signed in to leave a comment
Gellert Varga
3 July 2020, 09:50
1) "MEI 10 1980" - wrong.
Month in English: MAY , not MEI
2) (a.getMonth>5 && a.getMonth<9) - wrong.
Jan == 0 , Feb == 1 , so: June == 5 !!
3.) for(Map.Entry<String,Date> test:map.entrySet()) -- With this shorthand loop Java can not remove items.
For purpose of removing items, you should create iterator object.
0