forked from Yandex-Practicum/Java-Module-Project-YP
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCar.java
More file actions
41 lines (33 loc) · 934 Bytes
/
Car.java
File metadata and controls
41 lines (33 loc) · 934 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import java.util.Objects;
public final class Car {
private final String name;
private final double speed;
public Car(String name, double speed) {
this.name = name;
this.speed = speed;
}
public String name() {
return name;
}
public double speed() {
return speed;
}
@Override
public boolean equals(Object obj) {
if (obj == this) return true;
if (obj == null || obj.getClass() != this.getClass()) return false;
var that = (Car) obj;
return Objects.equals(this.name, that.name) &&
Double.doubleToLongBits(this.speed) == Double.doubleToLongBits(that.speed);
}
@Override
public int hashCode() {
return Objects.hash(name, speed);
}
@Override
public String toString() {
return "Car[" +
"name=" + name + ", " +
"speed=" + speed + ']';
}
}