import java.text.*;
import java.util.*;
class Eveniment {
private Date dataInceput, dataSfarsit
; // Primeste 2 stringuri in format yyyy-MM-dd HH:mm:ss reprezentand data si ora
// de inceput si de final a evenimentului si inca un string care contine numele
// cu care apare evenimentul in calendar
try {
this.dataInceput = format.parse(dataInceput);
this.dataSfarsit = format.parse(dataSfarsit);
System.
out.
println("Data nu este in formatul cerut!"); }
}
public Date getDataInceput
() { return dataInceput;
}
public Date getDataSfarsit
() { return dataSfarsit;
}
return nume;
}
}
class EvenimentRecurent extends Eveniment {
public static final long HOUR_IN_MSEC = 3600000;
private int numarOre;
public EvenimentRecurent
(String dataInceput,
String dataSfarsit,
String nume,
int numarOre
) { super(dataInceput, dataSfarsit, nume);
this.numarOre = numarOre;
}
Date timpCurent
= getDataInceput
(); try {
Date timpSpecific
= formatRecurent.
parse(dataEveniment
); timpCurent.setTime(timpCurent.getTime() + (timpSpecific.getTime() - timpCurent.getTime()) / (numarOre * HOUR_IN_MSEC) * numarOre * HOUR_IN_MSEC);
if (timpCurent.before(timpSpecific)) {
timpCurent.setTime(timpCurent.getTime() + numarOre * HOUR_IN_MSEC);
}
System.
out.
println("Data nu este in formatul cerut!"); return null;
}
return formatRecurent.format(timpCurent).toString();
}
}
public class Main {
public static void main
(String[] args
) { EvenimentRecurent er = new EvenimentRecurent("2019-03-09 22:46:00",
"2019-03-09 23:00:00", "Scris probleme", 24);
System.
out.
println(er.
urmatorulEveniment("2019-04-19 22:46:23")); }
}
CgppbXBvcnQgamF2YS50ZXh0Lio7CmltcG9ydCBqYXZhLnV0aWwuKjsKCmNsYXNzIEV2ZW5pbWVudCB7CiAgICBwcml2YXRlIERhdGUgZGF0YUluY2VwdXQsIGRhdGFTZmFyc2l0OwogICAgcHJpdmF0ZSBTdHJpbmcgbnVtZTsKICAgIC8vIFByaW1lc3RlIDIgc3RyaW5ndXJpIGluIGZvcm1hdCB5eXl5LU1NLWRkIEhIOm1tOnNzIHJlcHJlemVudGFuZCBkYXRhIHNpIG9yYQog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