Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package zadadamsandra;
- /**
- *
- * @author Hugon
- */
- import java.io.FileReader;
- import java.io.BufferedReader;
- import java.io.ObjectOutputStream;
- import java.io.FileOutputStream;
- import java.io.IOException;
- public class ZadAdamSandra {
- public static void Emerytura(String plik){
- try {
- String linia;
- FileReader plikWe = new FileReader( plik );
- BufferedReader czytacz = new BufferedReader( plikWe );
- while ( ( linia = czytacz.readLine() ) != null ){
- for (int i=0; i < linia.length(); i++){
- String nazwisko="";
- String wiek = "";
- char płeć=0;
- int em = 0;
- if (linia.charAt(i) == '-') {
- i++;
- while( linia.charAt(i) != '-'){
- nazwisko = nazwisko + linia.charAt(i);
- i++;
- }
- if (linia.charAt(i) == '-') {
- i++;
- if (linia.charAt(i) == 'k')
- płeć = 'k';
- if (linia.charAt(i) == 'm')
- płeć = 'm';
- }
- while ( linia.charAt(i) != '-')
- i++;
- if (linia.charAt(i) == '-') {
- i++;
- if (linia.charAt(i) != '='){
- wiek = wiek + linia.charAt(i);
- i++;
- wiek = wiek + linia.charAt(i);
- em = Integer.parseInt(wiek);
- }
- }
- if ( płeć == 'k' ) {
- em = (65-em)*12;
- FileOutputStream plikWy = new FileOutputStream ( "kobiety.bin" );
- ObjectOutputStream pisz = new ObjectOutputStream( plikWy );
- pisz.writeObject(nazwisko);
- pisz.writeObject(" ");
- pisz.writeObject(em);
- pisz.writeObject("\n");
- pisz.close();
- }
- if ( płeć == 'm' ) {
- em = (67-em)*12;
- FileOutputStream plikWy = new FileOutputStream ( "mężczyźni.bin" );
- ObjectOutputStream pisz = new ObjectOutputStream( plikWy );
- pisz.writeObject(nazwisko);
- pisz.writeObject(" ");
- pisz.writeObject(em);
- pisz.writeObject("\n");
- pisz.close();
- }
- }
- }
- }
- czytacz.close();
- }
- catch ( IOException e ) {}
- }
- public static void main(String[] args) {
- // TODO code application logic here
- Emerytura("ludzie.txt");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement