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
StarOverride
Instructions
In the Star
class, let's add a new constructor with the following arguments :
- the
name
- the position
x
- the position
y
- the position
z
- the
magnitude
It calls the constructor of the superclassCelestialObject
.
We will override the hashCode
and equals
, using the magnitude
property.
Finally, we rewrite the toString
method. The returned String must have the following format : <name> shines at the <magnitude> magnitude
Usage
Here is a possible ExerciseRunner.java to test your function :
public class ExerciseRunner {
public static void main(String[] args) {
Star star = new Star();
Star star2 = new Star();
Star proxima = new Star("Proxima", 18.389, 832.32, 218, 0.4);
System.out.println(star.toString());
System.out.println(proxima.toString());
System.out.println(star.equals(star2));
System.out.println(star.equals(proxima));
}
}
and its output :
$ javac *.java -d build
$ java -cp build ExerciseRunner
Soleil shines at the 0.000 magnitude
Proxima shines at the 0.400 magnitude
true
false
$