Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package egzamin2019c2;
- import java.io.IOException;
- import java.io.RandomAccessFile;
- public class Egzamin2019C2
- {
- static String zmniejszajaca(String plik)
- {
- String nazwaLeku;
- int cenaLekuPlik;
- int cenaLeku;
- boolean refundacja;
- long pointerPrzedCena;
- long pointerPoCenie;
- int cenaNajmniejsza = Integer.MAX_VALUE;
- String nazwaNajtanszegoLeku = "";
- try(RandomAccessFile raf = new RandomAccessFile(plik, "rw");)
- {
- while(raf.getFilePointer() < raf.length())
- {
- nazwaLeku = raf.readUTF();
- pointerPrzedCena = raf.getFilePointer();
- cenaLekuPlik = raf.readInt();
- pointerPoCenie = raf.getFilePointer();
- refundacja = raf.readBoolean();
- if(refundacja)
- {
- cenaLeku = (int)(cenaLekuPlik - cenaLekuPlik*0.15);
- raf.seek(pointerPrzedCena);
- raf.writeInt(cenaLeku);
- raf.seek(pointerPoCenie);
- }
- else
- cenaLeku = cenaLekuPlik;
- if(cenaLeku<cenaNajmniejsza)
- nazwaNajtanszegoLeku = nazwaLeku;
- }
- }
- catch(IOException e)
- { System.out.println("Wystąpił wyjątek" + e.getMessage());}
- return nazwaNajtanszegoLeku;
- }
- public static void main(String[] args)
- {
- // TODO code application logic here
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement