Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.IOException;
- import java.io.RandomAccessFile;
- public class Zadanie2 {
- public static String zwieksz(String nazwa) {
- String nazwisko_m="";
- int wiek_n = Integer.MAX_VALUE;
- try(RandomAccessFile raf = new RandomAccessFile(nazwa, "rw")){
- String nazwisko;
- int wiek;
- double pensja;
- char plec; // Przyjmuje ze plec K - kobieta M- mezczyzna
- long skok;
- long skok2;
- while(raf.getFilePointer() < raf.length()) {
- nazwisko = raf.readUTF();
- wiek = raf.readInt();
- skok = raf.getFilePointer(); // zapis pozycji aby ewentualnie nadpisac "pensja"
- pensja = raf.readDouble();
- plec = raf.readChar();
- skok2 = raf.getFilePointer();
- if(plec == 'K' && wiek > 50) {
- raf.seek(skok);
- raf.writeDouble(pensja * 1.05);
- raf.seek(skok2); // powrot do konca danej osoby
- }
- if(wiek < wiek_n) {
- nazwisko_m = nazwisko;
- }
- }
- }catch(IOException e) {
- e.getMessage();
- }
- return nazwisko_m;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement