Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public int processFile(String name, int quantity, int price) {
- int quantityCounter = 0;
- try {
- File inf = new File("input.txt");
- RandomAccessFile src = new RandomAccessFile(inf, "r");
- File outf = new File("output.txt");
- RandomAccessFile dst = new RandomAccessFile(outf, "rw");
- String line;
- while ((line = src.readLine()) != null) {
- String[]tmp = line.split(" ");
- if (tmp[0].equalsIgnoreCase(name)
- && Integer.valueOf(tmp[1]) > quantity
- && Integer.valueOf(tmp[2]) > price) {
- quantityCounter += Integer.valueOf(tmp[1]);
- int oldPrice = Integer.valueOf(tmp[2]);
- int newPrice = oldPrice * 90/100;
- line = (tmp[0] + " " + tmp[1] + " " + Integer.toString(newPrice));
- }
- dst.writeBytes(line);
- dst.writeByte(13);
- dst.writeByte(10);
- }
- src.close();
- dst.close();
- } catch (IOException e) {
- System.out.println("IOE:");
- e.printStackTrace();
- }
- return quantityCounter;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement