Guest User

Untitled

a guest
May 16th, 2018
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.99 KB | None | 0 0
  1.     public void setDatumRegistracije(String datumRegistracije) throws InvalidDatumException {
  2.         String date = datumRegistracije;
  3.         int duzina = date.length();
  4.         String dan = date.substring(0, 2);
  5.         String mesec = date.substring(3, 5);
  6.         String godina = date.substring(6, duzina);
  7.        
  8.         char[] input = date.toCharArray();
  9.        
  10.         if((input[0] < '0' || input[0] > '9') ||
  11.            (input[1] < '0' || input[1] > '9') ||
  12.            (input[2] != '/') ||
  13.            (input[3] < '0' || input[3] > '9') ||
  14.            (input[4] < '0' || input[4] > '9') ||
  15.            (input[5] != '/') ||
  16.            (input[6] < '0' || input[6] > '9') ||
  17.            (input[7] < '0' || input[7] > '9') ||
  18.            (input[8] < '0' || input[8] > '9') ||
  19.            (input[9] < '0' || input[9] > '9') ||
  20.            (duzina != 10)
  21.            )
  22.             throw new InvalidDatumException("Unesite datum u trazenom formatu!");
  23.         else {
  24.             int d = Integer.parseInt(dan);
  25.             int m = Integer.parseInt(mesec);
  26.             int y = Integer.parseInt(godina);
  27.             this.datumRegistracije.set(y, m-1, d);
  28.         }
  29.     }
Add Comment
Please, Sign In to add comment