Hi,
The last cindition fails and i do not know where i made an error. Maybe someone can help me?
Best Regards
Steffen
package de.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;
//import java.util.concurrent.ConcurrentHashMap;
import java.util.Iterator;
import java.util.Set;
/*
Die liebe Emma und die Sommerferien
*/
public class Solution {
public static class Debug{
public static boolean debug = false;
}
public static HashMap<String, Date> mapErstellen() 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"));
//schreib hier deinen Code
for(int i = 0; i < 9; i++){
Date temp = new Date();
temp.setDate(i*i % 30);
temp.setMonth(i % 12);
temp.setYear(i*i-1000*i+2000);
// not the best way to do something like this, but who cares
if(Debug.debug){
System.out.println(temp);
}
map.put("Stallone" + i, temp);
}
if(Debug.debug){
for(Map.Entry<String,Date> entry : map.entrySet()){
System.out.println(entry);
}
}
return map;
}
public static void alleSommergeburtstagskinderEntfernen(HashMap<String, Date> map) {
//schreib hier deinen Code
HashMap<String, Date> help = map;
int month = 0;
Set entrySet = help.entrySet();
Iterator it = entrySet.iterator();
while(it.hasNext()){
//for(Map.Entry<String,Date> entry : help.entrySet()){
//remove every entry wich was born in the summer
Map.Entry entry = (Map.Entry)it.next();
if(Debug.debug){
//System.out.println("Debug: " + entry);
System.out.println("Debug: " + entry.getKey());
System.out.println("Debug: " + entry.getValue());
}
Date tmp = (Date)entry.getValue();
month = tmp.getMonth();
if(Debug.debug){
System.out.println("Month: " + month);
}
if((month > 4) && (month <= 9)){
//help.remove(entry.getKey());
it.remove();
if(Debug.debug){
System.out.println("Removed: " + entry);
//System.out.println("Month: " + month);
//System.out.println("Added: " + entry);
}
}
}
if(Debug.debug){
System.out.println("Size at the end of the algo: " + help.size());
System.out.println("Map:" + map);
System.out.println("Help map : " + help);
}
//map = help;
}
public static void main(String[] args) {
HashMap<String,Date> map; //= new HashMap();
try{
map = mapErstellen();
}
catch(Exception e){
map = new HashMap<String,Date>();
}
alleSommergeburtstagskinderEntfernen(map);
if(Debug.debug){
for(Map.Entry<String,Date> entry : map.entrySet()){
System.out.println("Output: " + entry);
}
System.out.println(map);
}
}
}