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.
 
 
 
 
 
 
Abdelilah Khossan 78e9c1846c
CON-1881-Review-java-piscine-subjects-Fix-grammar-and-semantic-issues (#2102)
1 year ago
..
README.md CON-1881-Review-java-piscine-subjects-Fix-grammar-and-semantic-issues (#2102) 1 year ago

README.md

StarUtils

Instructions

Now, let's add some useful methods to our class.

First, toString method which returns a literal version of our class. The format is the following : <name> is positioned at (<x>, <y>, <z>). The printed double will have a precision of 3 decimals.

Then, equals(Object object) method which will return true if all properties of the object in parameter are equal to the current object.

As we have overriden equals method, we need to override hashCode method. This method returns an integer. If two objects are equal (using the equals method), then the results of their hashCode method should be equal.

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
$

Notions

Equals
HashCode
ToString