Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Person {
- private String imie;
- private String nazwisko;
- private int pesel;
- public Person (String arg1, String arg2, int arg3){
- setImie(arg1);
- setNazwisko(arg2);
- setPesel(arg3);
- }
- public Person() {
- ;
- }
- public String getImie() {
- return imie;
- }
- public void setImie(String imie) {
- this.imie = imie;
- }
- public String getNazwisko() {
- return nazwisko;
- }
- public void setNazwisko(String nazwisko) {
- this.nazwisko = nazwisko;
- }
- public int getPesel() {
- return pesel;
- }
- public void setPesel(int pesel) {
- this.pesel = pesel;
- }
- public void tozsamosc(){
- System.out.println("Czlowiek o Peselu " + pesel + " to " + imie + " " + nazwisko);
- }
- }
- import java.util.HashMap;
- import java.util.Map;
- public class Main {
- public static void main(String[] args) {
- Person osoba = new Person("Kamil","Makowski",99250);
- Person osoba2 = new Person("Mateusz","Wierzba",99222);
- Person osoba3 = new Person();
- Person osoba4 = new Person();
- Map<Integer, Person> map= new HashMap<Integer,Person>();
- map.put(osoba.getPesel(), osoba);
- map.put(osoba2.getPesel(), osoba2);
- boolean zawieraKlucz = map.containsKey(osoba.getPesel());
- boolean zawieraKlucz2 = map.containsKey(osoba2.getPesel());
- boolean zawieraKlucz3 = map.containsKey(9000);
- System.out.println("Czy mapa zawiera osobe o takim peselu : " + osoba.getPesel() + " ? " + zawieraKlucz);
- osoba3 = map.get(osoba.getPesel());
- osoba3.tozsamosc();
- System.out.println("A czy mapa zawiera osobe o takim peselu : " + osoba2.getPesel() + " ? " + zawieraKlucz2);
- osoba4 = map.get(osoba2.getPesel());
- osoba4.tozsamosc();
- System.out.println("A czy mapa zawiera osobe o takim peselu : " + 9000 + " ? " + zawieraKlucz3);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement