File tree 1 file changed +28
-2
lines changed
1 file changed +28
-2
lines changed Original file line number Diff line number Diff line change
1
+
2
+ import java .util .Objects ;
3
+
1
4
public class car {
2
5
private final String brand ;
3
6
private final String model ;
@@ -13,7 +16,30 @@ public class car {
13
16
this .price =price ;
14
17
this .color =color ;
15
18
}
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 ;
18
44
}
19
45
}
You can’t perform that action at this time.
0 commit comments