Skip to content

Instantly share code, notes, and snippets.

@RafaelAPB
Created September 23, 2015 21:21
Show Gist options
  • Save RafaelAPB/42bd9becef18a5b3451c to your computer and use it in GitHub Desktop.
Save RafaelAPB/42bd9becef18a5b3451c to your computer and use it in GitHub Desktop.
public class Cat () {
private String name;
private int age;
private double weight;
public Cat (String name, int age, double weight) {
this.name = name;
this.age = age;
this.weight = weight;
}
public String getName(){
return this.name;
}
public void setName (String name) {
this.name = name;
}
public int getAge (int age) {
return this.age;
}
public int setAge (int age) {
this.age = age;
}
public double getWeight (double weight) {
return this.weight;
}
public double setWeight (double weight) {
this.weight = weight;
}
@Override
public boolean equals(Object o) {
if (o instanceof Cat) {
Cat cat = (Cat) o;
return this.name.equals(cat.name) && this.age == cat.age && this.weight == cat.weight;
}
return false;
}
@Override
@SuppressWarnings("nls")
public String toString() {
return this.name + "(cat) (" + this.age + "," + this.weight + ")";
}
public class Application {
public static void main(String[] args) {
Cat cat = new Cat("Tareco", 12, 3.141);
System.out.println(cat.equals(new Cat("Tareco", 12, 3.141))); // prints "true"
System.out.println(cat.equals(new Cat("Pantufa", 1, 2.718))); // prints "false"
System.out.println(cat);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment