Advertisement
polpoteu

JAVA Egz Wynagrodzenie+

Mar 5th, 2019
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.47 KB | None | 0 0
  1. import java.io.IOException;
  2. import java.io.RandomAccessFile;
  3.  
  4. public class Zadanie2 {
  5.  
  6. public static String zwieksz(String nazwa) {
  7.  
  8. String nazwisko_m="";
  9. int wiek_n = Integer.MAX_VALUE;
  10. try(RandomAccessFile raf = new RandomAccessFile(nazwa, "rw")){
  11. String nazwisko;
  12. int wiek;
  13. double pensja;
  14. char plec; // Przyjmuje ze plec K - kobieta M- mezczyzna
  15.  
  16. long skok;
  17. long skok2;
  18. while(raf.getFilePointer() < raf.length()) {
  19.  
  20. nazwisko = raf.readUTF();
  21. wiek = raf.readInt();
  22.  
  23. skok = raf.getFilePointer(); // zapis pozycji aby ewentualnie nadpisac "pensja"
  24.  
  25. pensja = raf.readDouble();
  26. plec = raf.readChar();
  27. skok2 = raf.getFilePointer();
  28.  
  29. if(plec == 'K' && wiek > 50) {
  30.  
  31. raf.seek(skok);
  32.  
  33. raf.writeDouble(pensja * 1.05);
  34. raf.seek(skok2); // powrot do konca danej osoby
  35. }
  36.  
  37. if(wiek < wiek_n) {
  38. nazwisko_m = nazwisko;
  39. }
  40.  
  41. }
  42.  
  43.  
  44. }catch(IOException e) {
  45. e.getMessage();
  46. }
  47.  
  48.  
  49. return nazwisko_m;
  50. }
  51.  
  52.  
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement