-
-
Save carbide-public/77bdd596771a94c278a1fcd549706666 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Scanner; | |
public class Add implements Comparable<Add>{ | |
private String name; | |
private String lastName; | |
private int number; | |
public Add(String name, String lastName, int number) { | |
this.name = name; | |
this.lastName = lastName; | |
this.number = number; | |
} | |
public String getName() { | |
return name; | |
} | |
public void setName(String name) { | |
this.name = name; | |
} | |
public String getLastName() { | |
return lastName; | |
} | |
public void setLastName(String lastName) { | |
this.lastName = lastName; | |
} | |
public int getNumber() { | |
return number; | |
} | |
public void setNumber(int number) { | |
this.number = number; | |
} | |
@Override | |
public String toString() { | |
return "Imię: " + name + '\'' + | |
", Nazwisko = " + lastName + '\'' + | |
", Numer telefonu: " + number + | |
'}'; | |
} | |
@Override | |
public boolean equals(Object o) { | |
if (this == o) return true; | |
if (o == null || getClass() != o.getClass()) return false; | |
Add add = (Add) o; | |
if (number != add.number) return false; | |
if (name != null ? !name.equals(add.name) : add.name != null) return false; | |
return lastName != null ? lastName.equals(add.lastName) : add.lastName == null; | |
} | |
@Override | |
public int hashCode() { | |
int result = name != null ? name.hashCode() : 0; | |
result = 31 * result + (lastName != null ? lastName.hashCode() : 0); | |
result = 31 * result + number; | |
return result; | |
} | |
@Override | |
public int compareTo(Add o) { | |
if (number == o.getNumber()){ | |
return 0 ; | |
} else if (number > o.getNumber()){ | |
return 1; | |
} | |
return -1; | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment