I have to create a method called nextEvent
, which receives and returns a String
that represents a date in this pattern: "yyyy-MM-dd HH:mm:ss". I have to add an int
called nrHours
to this String
to modify the date when next event will be. My problem is that I don't know haw can I concatenate an int
onto a string
...
The code:
class Event {
private Date dateStart, dateEnd;
private String name;
public Event(String dateStart, String dateEnd, String name) {
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
try {
this.dateStart = format.parse(dateStart);
this.dateEnd = format.parse(dateEnd);
} catch (Exception e) {
System.out.println("Not valid date format");
}
this.name = name;
}
public Date getDateStart() {
return dateStart;
}
public Date getDateEnd() {
return dateEnd;
}
public String getNume() {
return name;
}
}
class EventRecurrent extends Event {
private int nrHours;
private Date next;
EventRecurrent(String dateStart, String dateEnd, String name, int nrHours) {
super(dateStart, dateEnd, name);
this.nrHours = nrHours;
}
public String nextEvent(String next) {
// I dont know how can I add the nrHours to the String next
return next;
}
}
public class Main {
public static void main(String[] args) {
EventRecurrent er = new EventRecurrent("2019-03-09 22:46:00",
"2019-03-09 23:00:00", "walk the dog", 24);
System.out.println(er.nextEvent("2019-04-19 22:46:23"));
// 2019-04-20 22:46:00
}
}
In the Main is an example: if the nextEvent receives "2019-04-19 22:46:23", and the nrHours is 24, then it should print out: 2019-04-20 22:46:00
java.text.* and java.util.* are imported