I did copy the code from someone else as it really became unproductive to keep trying to figure out how this works. Its way over my head. Can someone please point me in the right direction to get some more information on:
1- how to we work with date and time. I'm so confused there is so much information out there that I do not know where to start.
2. how does an iterator actually work? I'm really struggling with this topic and I read the articles more then once but the information is not enough to be able to do these tasks. Am I the only one that feels that codegym is now failing us as the lessons do not provide enough information to be able to do these task.
3. Is it normal that on average it takes me more than 2 hours per task?
I hope to hear from you!!
package com.codegym.task.task08.task0816;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
/*
Kind Emma and the summer holidays
*/
public class Solution {
public static HashMap<String, Date> createMap() throws ParseException {
/*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>();
*/
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"));
map.put("Stallone2", df.parse("JULY 1 1980"));
map.put("Stallone3", df.parse("AUGUST 5 1980"));
map.put("Stallone4", df.parse("JUNE 6 1980"));
map.put("Stallone5", df.parse("SEPTEMBER 6 1980"));
map.put("Stallone6", df.parse("OKTOBER 6 1980"));
map.put("Stallone7", df.parse("NOVEMBER 8 1980"));
map.put("Stallone8", df.parse("DECEMBER 8 1980"));
map.put("Stallone9", df.parse("DECEMBER 9 1980"));
map.put("Stallone10", df.parse("SEPTEMBER 9 1980"));
return map;
}
public static void removeAllSummerPeople(HashMap<String, Date> map) {
//write your code here
Calendar calendar = Calendar.getInstance(); // Date.getMonth is deprecated, we use Calendar;//copied this from someone else
Iterator<Map.Entry<String, Date>> iterator = map.entrySet().iterator();//create and intialize a initiator
while(iterator.hasNext())// check if there is a next element
{
Map.Entry<String, Date> entry = iterator.next();//get the next element instead of pair it is entry no idea why?
//if(pair.getValue().after(df.parse("JUNE 1 1980")) && pair.getValue().before(df.parse("AUGUST 31 1980"))) //not working
//if the date is after june 1 but before august 31. no idea how to do this
//if(df.parse(MMMMM == JUNE || MMMMM == JULY || MMMMM == AUGUST)) // not working eithercalendar.setTime(entry.getValue());
calendar.setTime(entry.getValue());// no idea what this is doing either
int month = calendar.get(Calendar.MONTH); // Month from 0 to 11, still clueless
if (month >= 5 && month < 8) //this part I get as the months's index starts with January = 0
{
iterator.remove();//remove this element from the map(iterator) why is it iterator and not map? Even more confused
}
}
}
/*
calendar.setTime(entry.getValue());
int month = calendar.get(Calendar.MONTH); // Month from 0 to 11
if (month >= 5 && month < 8) {
itr.remove();
}
}*/
public static void main(String[] args) {
}
}