Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package zad1b2017;
- import java.io.RandomAccessFile;
- /**
- *
- * @author Szymek
- */
- public class Zad1B2017 {
- /**
- * @param args the command line arguments
- */
- public static void main(String[] args)
- {
- }
- double funckja(String nazwaPliku, String nazwaTowaru)
- {
- double cena = 0;
- try(RandomAccessFile raf = new RandomAccessFile(nazwaPliku, "rw");)
- {
- int iloscTowarow = 0;
- long wielkoscPliku = raf.length();
- while(raf.getFilePointer() < wielkoscPliku)
- {
- String nazwaTowaruPlik = raf.readUTF();
- double cenaPlik = raf.readDouble();
- int liczbaSztuk = raf.readInt();
- iloscTowarow++;
- }
- String[] nazwaTab = new String[iloscTowarow];
- double[] cenaTab = new double[iloscTowarow];
- int[] lSztukTab = new int[iloscTowarow];
- int i = 0;
- while(raf.getFilePointer() < wielkoscPliku)
- {
- nazwaTab[i] = raf.readUTF();
- cenaTab[i] = raf.readDouble();
- lSztukTab[i] = raf.readInt();
- i++;
- }
- for(int j = 0; j<iloscTowarow; j++)
- {
- if(lSztukTab[j]>=100)
- cenaTab[j] = cena*0.90;
- if(nazwaTowaru == nazwaTab[j])
- cena = cenaTab[j];
- }
- raf.setLength(0);
- for(int k = 0; k<iloscTowarow; k++)
- {
- raf.writeUTF(nazwaTab[k]);
- raf.writeDouble(cenaTab[k]);
- raf.writeInt(lSztukTab[k]);
- }
- }
- catch(Exception e)
- { System.out.println("Wyjątek: " + e.getLocalizedMessage()); }
- return cena;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement