fork(1) download
  1. import java.util.*;
  2. import java.text.*;
  3.  
  4. class Eveniment {
  5. private Date dataInceput, dataSfarsit;
  6. private String nume;
  7. // Primeste 2 stringuri in format yyyy-MM-dd HH:mm:ss reprezentand data si ora
  8. // de inceput si de final a evenimentului si inca un string care contine numele
  9. // cu care apare evenimentul in calendar
  10. public Eveniment(String dataInceput, String dataSfarsit, String nume) {
  11. SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  12. try {
  13. this.dataInceput = format.parse(dataInceput);
  14. this.dataSfarsit = format.parse(dataSfarsit);
  15. } catch (Exception e) {
  16. System.out.println("Data nu este in formatul cerut!");
  17. }
  18. this.nume = nume;
  19. }
  20.  
  21. public Date getDataInceput() {
  22. return dataInceput;
  23. }
  24.  
  25. public Date getDataSfarsit() {
  26. return dataSfarsit;
  27. }
  28.  
  29. public String getNume() {
  30. return nume;
  31. }
  32. }
  33.  
  34. class EvenimentRecurent extends Eveniment{
  35. private Date data;
  36. private static int numarOre;
  37.  
  38. public EvenimentRecurent(String dataInceput, String dataSfarsit, String nume, int numarOre){
  39. super(dataInceput, dataSfarsit, nume);
  40. this.numarOre = numarOre;
  41. }
  42.  
  43. public String urmatorulEveniment(String datadata){
  44. SimpleDateFormat form = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  45. try {
  46. data = form.parse(datadata);
  47. } catch (Exception e) {
  48. System.out.println("Data nu este in formatul cerut!");
  49. }
  50. Date aux = getDataInceput();
  51. Calendar cal = Calendar.getInstance();
  52. cal.setTime(aux);
  53. Calendar c1 = Calendar.getInstance();
  54. c1.setTime(data);
  55. long seconds = (c1.getTimeInMillis() - cal.getTimeInMillis()) / 1000;
  56. long nrSec = this.numarOre * 3600;
  57. // int hours = (int) (seconds / 3600);
  58. //int s = (seconds/ 3600.0);
  59. long ev = (seconds / nrSec);
  60. cal.add(Calendar.SECOND, (ev * nrSec));
  61. if (seconds > (ev * nrSec)){
  62. cal.add(Calendar.SECOND, nrSec);
  63. }
  64. return form.format(cal.getTime());
  65. }
  66. }
  67.  
  68. class prog {
  69. public static void main(String[] args) {
  70. EvenimentRecurent er = new EvenimentRecurent("2019-03-09 22:46:00",
  71. "2019-03-09 23:00:00", "Scris probleme", 24);
  72. System.out.println(er.urmatorulEveniment("2019-04-19 22:46:23"));
  73. // 2019-04-20 22:46:00
  74. }
  75. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
Main.java:60: error: incompatible types: possible lossy conversion from long to int
        cal.add(Calendar.SECOND, (ev * nrSec));
                                     ^
Main.java:62: error: incompatible types: possible lossy conversion from long to int
        	cal.add(Calendar.SECOND, nrSec);
        	                         ^
Note: Some messages have been simplified; recompile with -Xdiags:verbose to get full output
2 errors
stdout
Standard output is empty