Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package aaa1;
- import java.io.*;
- import java.util.*;
- class NevazeciRacunException extends Exception {
- public NevazeciRacunException(String racun) {
- super(racun + "nije validan");
- }
- }
- class NeispravnaTransakcijaException extends Exception {
- public NeispravnaTransakcijaException (String trans) {
- super(trans+"transakcija je ne ispravna");
- }
- }
- class NeispravanIznosException extends Exception {
- public NeispravanIznosException (String iznos) {
- super(iznos + "iznos je neispravan");
- }
- }
- class NedostajePodatakException extends Exception {
- public NedostajePodatakException(String koji) {
- super("ne dostaje podatak o " +koji);
- }
- }
- public class aaa1 {
- public static void proveriRacun(String racun) throws NevazeciRacunException {
- boolean jeste = true;
- if(racun.length()!=8) {
- throw new NevazeciRacunException(racun);
- }
- for(int i =0;i<racun.length();i++) {
- char ch = racun.charAt(i);
- if(!((ch>0) && (ch<9)) && !((i==3) &&(ch=='-'))){
- jeste=false;
- }
- }
- if(!jeste) {
- throw new NevazeciRacunException(racun);
- }
- }
- public static void proveriTransakciju(String trans) throws NeispravnaTransakcijaException {
- if(!trans.equalsIgnoreCase("odliv") && !trans.equalsIgnoreCase("izliv")) {
- throw new NeispravnaTransakcijaException(trans);
- }
- }
- public static void proveriIznos(String iznos) throws NeispravanIznosException {
- try {
- Double.parseDouble(iznos);
- }catch(NumberFormatException e ) {
- throw new NeispravanIznosException(iznos);
- }
- }
- public static void main(String[] args) {
- try(BufferedReader in = new BufferedReader(new FileReader("fajl.txt"))) {
- int n = Integer.parseInt(in.readLine());
- for(int i =0;i<n;i++) {
- String racun = in.readLine();
- if(racun==null) {
- throw new NedostajePodatakException(racun);
- }
- proveriRacun(racun);
- String trans = in.readLine();
- if(trans == null) {
- throw new NedostajePodatakException(trans);
- }
- proveriTransakciju(trans);
- String iznos = in.readLine();
- if(iznos==null) {
- throw new NedostajePodatakException(trans);
- }
- proveriIznos(iznos);
- }
- System.out.println("Validacija fajla uspesno izvrsena");
- }catch(IOException|NumberFormatException|NeispravanIznosException|NeispravnaTransakcijaException|NevazeciRacunException|NedostajePodatakException e) {
- System.out.println(e.getMessage());
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement