Advertisement
Guest User

piijp22

a guest
Oct 21st, 2012
217
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.34 KB | None | 0 0
  1.    public int processFile(String name, int quantity, int price) {
  2.             int quantityCounter = 0;
  3.             try {
  4.             File inf = new File("input.txt");
  5.             RandomAccessFile src = new RandomAccessFile(inf, "r");
  6.      
  7.             File outf = new File("output.txt");
  8.             RandomAccessFile dst = new RandomAccessFile(outf, "rw");
  9.          
  10.             String line;
  11.             while ((line = src.readLine()) != null) {
  12.               String[]tmp = line.split(" ");  
  13.              
  14.               if (tmp[0].equalsIgnoreCase(name)
  15.                       && Integer.valueOf(tmp[1]) > quantity
  16.                       && Integer.valueOf(tmp[2]) > price) {
  17.              
  18.                     quantityCounter += Integer.valueOf(tmp[1]);    
  19.                     int oldPrice = Integer.valueOf(tmp[2]);
  20.                     int newPrice = oldPrice * 90/100;
  21.              
  22.                     line = (tmp[0] + " " + tmp[1] + " " + Integer.toString(newPrice));
  23.                 }              
  24.                 dst.writeBytes(line);
  25.                 dst.writeByte(13);
  26.                 dst.writeByte(10);
  27.             }
  28.             src.close();
  29.             dst.close();
  30.         } catch (IOException e) {
  31.             System.out.println("IOE:");
  32.             e.printStackTrace();
  33.         }
  34.        return quantityCounter;
  35.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement