Skip to content

Instantly share code, notes, and snippets.

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