Advertisement
Guest User

Untitled

a guest
Dec 19th, 2014
179
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.47 KB | None | 0 0
  1. package aaa1;
  2. import java.io.*;
  3. import java.util.*;
  4. class NevazeciRacunException extends Exception {
  5.     public NevazeciRacunException(String racun) {
  6.         super(racun + "nije validan");
  7.     }
  8. }
  9.  
  10. class NeispravnaTransakcijaException extends Exception {
  11.     public NeispravnaTransakcijaException (String trans) {
  12.         super(trans+"transakcija je ne ispravna");
  13.     }
  14. }
  15.  
  16. class NeispravanIznosException extends Exception {
  17.     public NeispravanIznosException (String iznos) {
  18.         super(iznos + "iznos je neispravan");
  19.     }
  20. }
  21.  
  22. class NedostajePodatakException extends Exception {
  23.     public NedostajePodatakException(String koji) {
  24.         super("ne dostaje podatak o " +koji);
  25.     }
  26. }
  27. public class aaa1 {
  28.     public static void proveriRacun(String racun) throws NevazeciRacunException {
  29.         boolean jeste  = true;
  30.         if(racun.length()!=8) {
  31.             throw new NevazeciRacunException(racun);
  32.         }
  33.         for(int i =0;i<racun.length();i++) {
  34.             char ch = racun.charAt(i);
  35.             if(!((ch>0) && (ch<9)) && !((i==3) &&(ch=='-'))){
  36.                 jeste=false;
  37.             }
  38.  
  39.  
  40.         }
  41.         if(!jeste) {
  42.             throw new NevazeciRacunException(racun);
  43.         }
  44.     }
  45.     public static void proveriTransakciju(String trans) throws NeispravnaTransakcijaException {
  46.         if(!trans.equalsIgnoreCase("odliv") && !trans.equalsIgnoreCase("izliv")) {
  47.             throw new NeispravnaTransakcijaException(trans);
  48.         }
  49.     }
  50.  
  51.     public static void proveriIznos(String iznos) throws NeispravanIznosException {
  52.         try {
  53.             Double.parseDouble(iznos);
  54.         }catch(NumberFormatException e ) {
  55.             throw new NeispravanIznosException(iznos);
  56.         }
  57.     }
  58.  
  59.     public static void main(String[] args) {
  60.         try(BufferedReader in = new BufferedReader(new FileReader("fajl.txt"))) {
  61.             int n = Integer.parseInt(in.readLine());
  62.             for(int i =0;i<n;i++) {
  63.                 String racun = in.readLine();
  64.                 if(racun==null) {
  65.                     throw new NedostajePodatakException(racun);
  66.                 }
  67.                 proveriRacun(racun);
  68.                 String trans = in.readLine();
  69.                 if(trans == null) {
  70.                     throw new NedostajePodatakException(trans);
  71.                 }
  72.                 proveriTransakciju(trans);
  73.                 String iznos = in.readLine();
  74.                 if(iznos==null) {
  75.                     throw new NedostajePodatakException(trans);
  76.                 }
  77.                 proveriIznos(iznos);
  78.  
  79.             }
  80.             System.out.println("Validacija fajla uspesno izvrsena");
  81.         }catch(IOException|NumberFormatException|NeispravanIznosException|NeispravnaTransakcijaException|NevazeciRacunException|NedostajePodatakException e) {
  82.             System.out.println(e.getMessage());
  83.         }
  84.     }
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement