leniuch

apteka

Feb 25th, 2020
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.92 KB | None | 0 0
  1. public class raf {
  2.  
  3.     static String apteka(String plik) throws FileNotFoundException{
  4.     int porown = 9999;
  5.     String najtanszy = " ";  
  6.    
  7.     try{
  8.        
  9.     RandomAccessFile raf = new RandomAccessFile(plik, "rw");
  10.     String line;
  11.    
  12.     while( (line = raf.readLine())!= null){
  13.     String lek = line;
  14.     long pos1 = raf.getFilePointer();
  15.     int cena = Integer.parseInt(raf.readLine());
  16.     Boolean refund = Boolean.parseBoolean(raf.readLine());
  17.     long pos2 = raf.getFilePointer();
  18.    
  19.     if(refund) {
  20.     raf.seek(pos1);
  21.     raf.writeBytes(Long.toString(Math.round(cena*0.85)));
  22.    
  23.     String cenaxd = Long.toString(Math.round(cena*0.85));
  24.     cena = Integer.parseInt(cenaxd);
  25.     raf.seek(pos2);
  26.     }
  27.    
  28.    
  29.     if(cena<porown){
  30.         porown=cena;
  31.         najtanszy=lek;}
  32.    
  33.     }
  34.    
  35.     }
  36.     catch(Exception e){System.out.println(e);}
  37.    
  38.    
  39.    
  40.     return najtanszy;}
Add Comment
Please, Sign In to add comment