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!"); }
this.nume = nume;
}
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 {
while (timpCurent.before(formatRecurent.parse(dataEveniment))) {
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-05-09 22:46:00",
"2019-03-09 23:00:00", "Scris probleme", 24);
System.
out.
println(er.
urmatorulEveniment("2019-05-09 22:46:00")); // 2019-04-20 22:46:00
}
}
aW1wb3J0IGphdmEudGV4dC4qOwppbXBvcnQgamF2YS51dGlsLio7CgpjbGFzcyBFdmVuaW1lbnQgewogICAgcHJpdmF0ZSBEYXRlIGRhdGFJbmNlcHV0LCBkYXRhU2ZhcnNpdDsKICAgIHByaXZhdGUgU3RyaW5nIG51bWU7CiAgICAvLyBQcmltZXN0ZSAyIHN0cmluZ3VyaSBpbiBmb3JtYXQgeXl5eS1NTS1kZCBISDptbTpzcyByZXByZXplbnRhbmQgZGF0YSBzaSBvcmEKICAgIC8vIGRlIGluY2VwdXQgc2kgZGUgZmluYWwgYSBldmVuaW1lbnR1bHVpIHNpIGluY2EgdW4gc3RyaW5nIGNhcmU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