Skip to content

Instantly share code, notes, and snippets.

@carbide-public
Forked from antimatter15/Add
Created November 28, 2017 07:55
Show Gist options
  • Save carbide-public/052577ee4ba980f957958d9b5d450b6b to your computer and use it in GitHub Desktop.
Save carbide-public/052577ee4ba980f957958d9b5d450b6b to your computer and use it in GitHub Desktop.
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