Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Gamrat{
- public static int ObliczZamowienie(String PlikD, String nazwa) //nazwa = Brokuł
- {
- int numerzamowienia;
- String nazwatowaru;
- double cena;
- int lsztuk, liczba = 0, i=1;
- boolean KPD = false;
- try(RandomAccesFile RAF = new RandomAccesFile(PlikD,"rw")
- {
- long rozmiarD = RAF.length()-1;
- while(!KPD)
- {
- if(RAF.getFilePointer() >= rozmiarD) KPD = true;
- //1Brokuł122.250
- numerzamowienia = RAF.readInt();
- nazwatowaru= RAF.readUTF();
- cena = RAF.readDouble();
- lsztuk = RAF.readInt();
- if(cena>50 && lsztuk>=25)
- {
- RAF.seek(RAF.getFilePointer()-Double.BYTES-Integer.BYTES); //cenalsztuk
- //55.027
- RAF.writeDouble(cena*0.9); //49.527
- RAF.seek(RAF.getFilePointer()+Interger.BYTES); //49.527
- }
- if(nazwatowaru == nazwa) { liczba = lsztuk;}
- }
- }
- catch(IOException e)
- {
- System.out.println("blad pliku" + e.getMessage());
- }
- catch(FileNotFoundException e)
- {
- System.out.println("brak pliku" + e.getMessage());
- }
- return liczba;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment