Skip to content

Commit b56de6a

Browse files
authored
Update car.java
1 parent 5820ba9 commit b56de6a

File tree

1 file changed

+28
-2
lines changed

1 file changed

+28
-2
lines changed

1-1/car.java

+28-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
2+
import java.util.Objects;
3+
14
public class car {
25
private final String brand;
36
private final String model;
@@ -13,7 +16,30 @@ public class car {
1316
this.price=price;
1417
this.color=color;
1518
}
16-
public void toString(){
17-
System.out.println(brand+" "+model+" "+hp+" "+cc+" "+price+" "+color);
19+
@Override
20+
public String toString(){
21+
return brand+" "+model+" "+hp+" "+cc+" "+price+" "+color;
22+
}
23+
@Override
24+
public boolean equals(Object obj) {
25+
if(obj == null) return false;
26+
if (obj instanceof car) {
27+
car PersonObj=(car) obj;
28+
if(this.toString().equals(PersonObj.toString()))
29+
return true;
30+
}
31+
return false;
32+
}
33+
34+
@Override
35+
public int hashCode() {
36+
int hash = 3;
37+
hash = 97 * hash + Objects.hashCode(this.brand);
38+
hash = 97 * hash + Objects.hashCode(this.model);
39+
hash = 97 * hash + this.hp;
40+
hash = 97 * hash + this.cc;
41+
hash = 97 * hash + this.price;
42+
hash = 97 * hash + Objects.hashCode(this.color);
43+
return hash;
1844
}
1945
}

0 commit comments

Comments
 (0)