Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- import java.io.*;
- public class pracownik
- {
- double pensja;
- int staz;
- long pesel;
- String imie ;
- String nazwisko;
- pracownik()
- {
- nazwisko = "Wierzbicki";
- imie = "Kuba";
- pesel = 999999999;
- pensja = 3000;
- staz = 5;
- }
- pracownik(String nazwisko,String imie,long pesel,int staz,double pensja)
- {
- this.nazwisko = nazwisko;
- this.imie = imie;
- this.pesel = pesel;
- this.staz = staz;
- this.pensja = pensja;
- }
- void wyswietl()
- {
- System.out.format("I %-15sI %-15sI %-15dI %-15dI %-15.2f I",nazwisko,imie,pesel,staz,pensja);
- System.out.println();
- }
- void toString(String nazwisko,String imie,long pesel,int staz,double pensja)
- {
- String results = String.format("I %-15sI %-15sI %-15sI %-15sI %-15s I",nazwisko,imie,pesel,staz,pensja);
- System.out.println(results);
- }
- public static void main(String[] args)
- {
- try
- {
- DataOutputStream strumień = new DataOutputStream(new FileOutputStream("plik.txt"));
- // test wyswietl
- // final pracownik pierwszy = new pracownik("Golka","Sebastian",951208110,2,4000);
- // pierwszy.wyswietl();
- // test toString
- // final pracownik pierwszy = new pracownik();
- // pierwszy.toString("Bakiewicz", "Kapsel", 9999999, 5, 4000);
- Scanner dane = new Scanner(System.in);
- pracownik tab [] = new pracownik[2];
- for(int i=0;i<2;i++)
- {
- /*System.out.println("Czy chcesz dodac pracownika? t/n");
- String koniec = dane.nextLine();
- if (koniec == "n")break;*/
- System.out.println("Podaj nazwisko: ");
- String Snaz = dane.nextLine();
- System.out.println("Podaj imię: ");
- String Simie = dane.nextLine();
- System.out.println("Podaj pesel: ");
- long Spes = dane.nextLong();
- System.out.println("Podaj staz: ");
- int Sstaz = dane.nextInt();
- System.out.println("Podaj pensje: ");
- double Spen = dane.nextDouble();
- System.out.println("");
- pracownik prac = new pracownik(Snaz,Simie,Spes,Sstaz,Spen);
- tab[i]=prac;
- }
- String na = "Nazwisko";
- String im = "Imie";
- String pes = "Pesel";
- String st = "Staż ";
- String pen = "Pensja";
- System.out.println("---------------------------------------------------------------------------------------");
- System.out.format("I %-15sI %-15sI %-15sI %-15sI %-15s I", na, im , pes, st, pen);
- System.out.println();
- System.out.println("---------------------------------------------------------------------------------------");
- for(int i=0;i<100;i++)
- {
- tab[i].wyswietl();
- }
- System.out.println("---------------------------------------------------------------------------------------");
- dane.close();
- strumień.close();
- }
- catch(FileNotFoundException e)
- {
- System.out.println("Nie znaleziono pliku");
- } catch(IOException e)
- {
- System.out.println("Błąd wejścia-wyjścia");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement