Advertisement
Guest User

Untitled

a guest
Mar 28th, 2017
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.74 KB | None | 0 0
  1. public class Person {
  2. private String imie;
  3. private String nazwisko;
  4. private int pesel;
  5.  
  6. public Person (String arg1, String arg2, int arg3){
  7. setImie(arg1);
  8. setNazwisko(arg2);
  9. setPesel(arg3);
  10. }
  11. public Person() {
  12. ;
  13. }
  14. public String getImie() {
  15. return imie;
  16. }
  17. public void setImie(String imie) {
  18. this.imie = imie;
  19. }
  20. public String getNazwisko() {
  21. return nazwisko;
  22. }
  23. public void setNazwisko(String nazwisko) {
  24. this.nazwisko = nazwisko;
  25. }
  26. public int getPesel() {
  27. return pesel;
  28. }
  29. public void setPesel(int pesel) {
  30. this.pesel = pesel;
  31. }
  32.  
  33. public void tozsamosc(){
  34. System.out.println("Czlowiek o Peselu " + pesel + " to " + imie + " " + nazwisko);
  35. }
  36. }
  37.  
  38.  
  39.  
  40. import java.util.HashMap;
  41. import java.util.Map;
  42. public class Main {
  43. public static void main(String[] args) {
  44. Person osoba = new Person("Kamil","Makowski",99250);
  45. Person osoba2 = new Person("Mateusz","Wierzba",99222);
  46. Person osoba3 = new Person();
  47. Person osoba4 = new Person();
  48. Map<Integer, Person> map= new HashMap<Integer,Person>();
  49. map.put(osoba.getPesel(), osoba);
  50. map.put(osoba2.getPesel(), osoba2);
  51. boolean zawieraKlucz = map.containsKey(osoba.getPesel());
  52. boolean zawieraKlucz2 = map.containsKey(osoba2.getPesel());
  53. boolean zawieraKlucz3 = map.containsKey(9000);
  54. System.out.println("Czy mapa zawiera osobe o takim peselu : " + osoba.getPesel() + " ? " + zawieraKlucz);
  55. osoba3 = map.get(osoba.getPesel());
  56. osoba3.tozsamosc();
  57. System.out.println("A czy mapa zawiera osobe o takim peselu : " + osoba2.getPesel() + " ? " + zawieraKlucz2);
  58. osoba4 = map.get(osoba2.getPesel());
  59. osoba4.tozsamosc();
  60. System.out.println("A czy mapa zawiera osobe o takim peselu : " + 9000 + " ? " + zawieraKlucz3);
  61. }
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement