mirror of https://github.com/01-edu/public.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
zanninso
2632926739
|
1 year ago | |
---|---|---|
.. | ||
README.md | 1 year ago |
README.md
StarUtils
Instructions
Now, some utils method for our class.
First, the toString
method which will return a literal version of our class. The format is the following : <name> is positioned at (<x>, <y>, <z>)
. The printed double will be with 3 decimals.
Then, the equals(Object object)
method which will return trus if all properties of the object as parameters are equals to the current object.
As we have rewritten the equals
method, we need to rewrite the hashCode
method. This method returns an integer. If two objects are equals (using the equals
method), then the results of their hashCode method should be equals.
Usage
Here is a possible ExerciseRunner.java to test your function :
public class ExerciseRunner {
public static void main(String[] args) {
CelestialObject celestialObject = new CelestialObject();
CelestialObject earth = new CelestialObject("Terre", 1.0, 2.0, 2.0);
CelestialObject earth1 = new CelestialObject("Terre", 1.0, 2.0, 2.0);
System.out.println(earth.toString());
System.out.println(earth.equals(earth1));
System.out.println(earth.equals(celestialObject));
System.out.println(earth.hashCode());
System.out.println(celestialObject.hashCode());
}
}
and its output :
$ javac *.java -d build
$ java -cp build ExerciseRunner
Terre is positioned at (1.000, 2.000, 2.000)
true
false
2129490293
-1811995559
$