Advertisement
Guest User

Untitled

a guest
Jan 31st, 2015
183
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.46 KB | None | 0 0
  1. /*
  2. * To change this license header, choose License Headers in Project Properties.
  3. * To change this template file, choose Tools | Templates
  4. * and open the template in the editor.
  5. */
  6. package zadadamsandra;
  7.  
  8. /**
  9. *
  10. * @author Hugon
  11. */
  12. import java.io.FileReader;
  13. import java.io.BufferedReader;
  14. import java.io.ObjectOutputStream;
  15. import java.io.FileOutputStream;
  16. import java.io.IOException;
  17.  
  18. public class ZadAdamSandra {
  19.  
  20. public static void Emerytura(String plik){
  21. try {
  22. String linia;
  23. FileReader plikWe = new FileReader( plik );
  24. BufferedReader czytacz = new BufferedReader( plikWe );
  25.  
  26.  
  27.  
  28. while ( ( linia = czytacz.readLine() ) != null ){
  29.  
  30.  
  31. for (int i=0; i < linia.length(); i++){
  32. String nazwisko="";
  33. String wiek = "";
  34. char płeć=0;
  35. int em = 0;
  36. if (linia.charAt(i) == '-') {
  37. i++;
  38. while( linia.charAt(i) != '-'){
  39. nazwisko = nazwisko + linia.charAt(i);
  40. i++;
  41. }
  42. if (linia.charAt(i) == '-') {
  43. i++;
  44. if (linia.charAt(i) == 'k')
  45. płeć = 'k';
  46. if (linia.charAt(i) == 'm')
  47. płeć = 'm';
  48. }
  49. while ( linia.charAt(i) != '-')
  50. i++;
  51. if (linia.charAt(i) == '-') {
  52. i++;
  53. if (linia.charAt(i) != '='){
  54. wiek = wiek + linia.charAt(i);
  55. i++;
  56. wiek = wiek + linia.charAt(i);
  57. em = Integer.parseInt(wiek);
  58. }
  59. }
  60. if ( płeć == 'k' ) {
  61. em = (65-em)*12;
  62. FileOutputStream plikWy = new FileOutputStream ( "kobiety.bin" );
  63. ObjectOutputStream pisz = new ObjectOutputStream( plikWy );
  64.  
  65. pisz.writeObject(nazwisko);
  66. pisz.writeObject(" ");
  67. pisz.writeObject(em);
  68. pisz.writeObject("\n");
  69. pisz.close();
  70. }
  71.  
  72. if ( płeć == 'm' ) {
  73. em = (67-em)*12;
  74. FileOutputStream plikWy = new FileOutputStream ( "mężczyźni.bin" );
  75. ObjectOutputStream pisz = new ObjectOutputStream( plikWy );
  76.  
  77. pisz.writeObject(nazwisko);
  78. pisz.writeObject(" ");
  79. pisz.writeObject(em);
  80. pisz.writeObject("\n");
  81. pisz.close();
  82. }
  83. }
  84.  
  85. }
  86.  
  87. }
  88. czytacz.close();
  89.  
  90. }
  91. catch ( IOException e ) {}
  92.  
  93.  
  94. }
  95. public static void main(String[] args) {
  96. // TODO code application logic here
  97. Emerytura("ludzie.txt");
  98. }
  99.  
  100. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement