Advertisement
Guest User

Untitled

a guest
Mar 3rd, 2016
233
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.86 KB | None | 0 0
  1. import java.util.*;
  2. import java.io.*;
  3. public class pracownik
  4. {
  5. double pensja;
  6. int staz;
  7. long pesel;
  8. String imie ;
  9. String nazwisko;
  10. pracownik()
  11. {
  12. nazwisko = "Wierzbicki";
  13. imie = "Kuba";
  14. pesel = 999999999;
  15. pensja = 3000;
  16. staz = 5;
  17. }
  18. pracownik(String nazwisko,String imie,long pesel,int staz,double pensja)
  19. {
  20. this.nazwisko = nazwisko;
  21. this.imie = imie;
  22. this.pesel = pesel;
  23. this.staz = staz;
  24. this.pensja = pensja;
  25. }
  26. void wyswietl()
  27. {
  28. System.out.format("I %-15sI %-15sI %-15dI %-15dI %-15.2f I",nazwisko,imie,pesel,staz,pensja);
  29. System.out.println();
  30. }
  31. void toString(String nazwisko,String imie,long pesel,int staz,double pensja)
  32. {
  33. String results = String.format("I %-15sI %-15sI %-15sI %-15sI %-15s I",nazwisko,imie,pesel,staz,pensja);
  34. System.out.println(results);
  35. }
  36.  
  37. public static void main(String[] args)
  38. {
  39. try
  40. {
  41. DataOutputStream strumień = new DataOutputStream(new FileOutputStream("plik.txt"));
  42.  
  43. // test wyswietl
  44. // final pracownik pierwszy = new pracownik("Golka","Sebastian",951208110,2,4000);
  45. // pierwszy.wyswietl();
  46.  
  47. // test toString
  48. // final pracownik pierwszy = new pracownik();
  49. // pierwszy.toString("Bakiewicz", "Kapsel", 9999999, 5, 4000);
  50.  
  51. Scanner dane = new Scanner(System.in);
  52.  
  53. pracownik tab [] = new pracownik[2];
  54. for(int i=0;i<2;i++)
  55. {
  56. /*System.out.println("Czy chcesz dodac pracownika? t/n");
  57. String koniec = dane.nextLine();
  58. if (koniec == "n")break;*/
  59. System.out.println("Podaj nazwisko: ");
  60. String Snaz = dane.nextLine();
  61. System.out.println("Podaj imię: ");
  62. String Simie = dane.nextLine();
  63. System.out.println("Podaj pesel: ");
  64. long Spes = dane.nextLong();
  65. System.out.println("Podaj staz: ");
  66. int Sstaz = dane.nextInt();
  67. System.out.println("Podaj pensje: ");
  68. double Spen = dane.nextDouble();
  69. System.out.println("");
  70. pracownik prac = new pracownik(Snaz,Simie,Spes,Sstaz,Spen);
  71. tab[i]=prac;
  72. }
  73.  
  74. String na = "Nazwisko";
  75. String im = "Imie";
  76. String pes = "Pesel";
  77. String st = "Staż ";
  78. String pen = "Pensja";
  79. System.out.println("---------------------------------------------------------------------------------------");
  80. System.out.format("I %-15sI %-15sI %-15sI %-15sI %-15s I", na, im , pes, st, pen);
  81. System.out.println();
  82. System.out.println("---------------------------------------------------------------------------------------");
  83. for(int i=0;i<100;i++)
  84. {
  85. tab[i].wyswietl();
  86. }
  87. System.out.println("---------------------------------------------------------------------------------------");
  88. dane.close();
  89. strumień.close();
  90. }
  91. catch(FileNotFoundException e)
  92. {
  93. System.out.println("Nie znaleziono pliku");
  94. } catch(IOException e)
  95. {
  96. System.out.println("Błąd wejścia-wyjścia");
  97. }
  98.  
  99. }
  100.  
  101. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement