Skip to content

Instantly share code, notes, and snippets.

@javabuddy
Created June 20, 2020 09:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save javabuddy/ff9c0812816a0765b3c3fbb19f401014 to your computer and use it in GitHub Desktop.
Save javabuddy/ff9c0812816a0765b3c3fbb19f401014 to your computer and use it in GitHub Desktop.
Code for Book class in Java
public class Book {
private final String name;
private final double price;public Star(String name, double price) {
this.name = name;
this.price = price;
}
@Override
public int hashCode() {
int hash = 7;
hash = 23 * hash + Objects.hashCode(this.name);
return hash;
}
@Override
public boolean equals(Object obj) {
if (obj == null) {
return false;
}if (getClass() != obj.getClass()) {
return false;
}final Test other = (Test) obj;if (!Objects.equals(this.name, other.name)) {
return false;
}if (Double.doubleToLongBits(this.price) != Double.doubleToLongBits(other.price)) {
return false;
}
return true;
}
@Override
public String toString() {
return "Test{" + "name=" + name + ", price=" + price + '}';
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment