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.

58 lines
1.7 KiB

## StarGalaxy
### Instructions
Create a new class `Galaxy` in a file named `Galaxy.java`.
It has one private property : `celestialObjects` of type `List<CelestialObject>`.
CON-1881-Review-java-piscine-subjects-Fix-grammar-and-semantic-issues (#2102) * docs(java piscine): Review and update AdventureAbstract exercise * docs(java piscine): Review AdventureCharacter subject * docs(java piscine): Review AdventureInterface subject * docs(java piscine): Review AdventureMonster subject * docs(java piscine): review AdventureSorcerer subject * docs(java piscine): Review AdventureTemplar subject * docs(java piscine): Review AdventureUtils subject * docs(java piscine): Review AdventureWeapon subject * docs(java piscine): Review ComputeArray subject * docs(java piscine): Review FileSearch subject * docs(java piscine): Review FormatDate subject * docs(java piscine): Review KeepTheChange subject * docs(java piscine): Review ListEquals subject * docs(java piscine): Review MapInventory subject * docs(java piscine): Review Observer subject * docs(java piscine): Review Palindrome subject * docs(java piscine): Review RegexReplace subject * docs(java piscine): Review Singleton subject * docs(java piscine): Review StarConstructors subject * docs(java piscine): Review StarGalaxy subject * docs(java piscine): Review StarMass subject * docs(java piscine): Review StarOverride subject * docs(java piscine): Review StarPlanet subject * docs(java piscine): Review StarProperties subject * docs(java piscine): Review StarStatic subject * docs(java piscine): Review StarUtils subject * docs(java piscine): Review StreamCollect subject * docs(java piscine): Review StreamMap subject * docs(java piscine): Review StreamReduce subject * docs(java piscine): Review StringConcat subject * docs(java piscine): Review StringContains subject * docs(java piscine): Review Wedding subject * docs(java piscine): Review WeddingComplex subject * docs(java piscine): Change a part of RegexReplace subject * docs(java piscine): Update AdventureAbstract subject * docs(java piscine): Fix wrong naming parameter -> attribute * docs(java piscine): Remove empty lines * docs(java piscine): Remove ## from line
1 year ago
It has one constructor with no parameters, which initialises `celestialObjects` property with an empty list.
CON-1881-Review-java-piscine-subjects-Fix-grammar-and-semantic-issues (#2102) * docs(java piscine): Review and update AdventureAbstract exercise * docs(java piscine): Review AdventureCharacter subject * docs(java piscine): Review AdventureInterface subject * docs(java piscine): Review AdventureMonster subject * docs(java piscine): review AdventureSorcerer subject * docs(java piscine): Review AdventureTemplar subject * docs(java piscine): Review AdventureUtils subject * docs(java piscine): Review AdventureWeapon subject * docs(java piscine): Review ComputeArray subject * docs(java piscine): Review FileSearch subject * docs(java piscine): Review FormatDate subject * docs(java piscine): Review KeepTheChange subject * docs(java piscine): Review ListEquals subject * docs(java piscine): Review MapInventory subject * docs(java piscine): Review Observer subject * docs(java piscine): Review Palindrome subject * docs(java piscine): Review RegexReplace subject * docs(java piscine): Review Singleton subject * docs(java piscine): Review StarConstructors subject * docs(java piscine): Review StarGalaxy subject * docs(java piscine): Review StarMass subject * docs(java piscine): Review StarOverride subject * docs(java piscine): Review StarPlanet subject * docs(java piscine): Review StarProperties subject * docs(java piscine): Review StarStatic subject * docs(java piscine): Review StarUtils subject * docs(java piscine): Review StreamCollect subject * docs(java piscine): Review StreamMap subject * docs(java piscine): Review StreamReduce subject * docs(java piscine): Review StringConcat subject * docs(java piscine): Review StringContains subject * docs(java piscine): Review Wedding subject * docs(java piscine): Review WeddingComplex subject * docs(java piscine): Change a part of RegexReplace subject * docs(java piscine): Update AdventureAbstract subject * docs(java piscine): Fix wrong naming parameter -> attribute * docs(java piscine): Remove empty lines * docs(java piscine): Remove ## from line
1 year ago
We add a getter for `celestialObjects` property (`getCelestialObjects`).
We create a new method `addCelestialObject` with a `CelestialObject` argument. This method adds the object in parameter to the `celestialObjects` list.
### Usage
Here is a possible ExerciseRunner.java to test your function :
```java
import java.util.List;
public class ExerciseRunner {
public static void main(String[] args) {
Galaxy galaxy = new Galaxy();
CelestialObject lune = new CelestialObject("Lune", -123.12, 392.238, 32.31);
Star betelgeuse = new Star("Betelgeuse", 128.23, -12.82, 32.328, 1289.3);
Planet naboo = new Planet("Naboo", 17.4389, 8349.1, 8943.92, betelgeuse);
galaxy.addCelestialObject(lune);
galaxy.addCelestialObject(betelgeuse);
galaxy.addCelestialObject(naboo);
List<CelestialObject> celestialObjects = galaxy.getCelestialObjects();
for (CelestialObject celestialObject : celestialObjects) {
System.out.println(celestialObject.toString());
}
}
}
```
and its output :
```shell
$ javac *.java -d build
$ java -cp build ExerciseRunner
Lune is positioned at (-123,120, 392,238, 32,310)
Betelgeuse shines at the 1289.300 magnitude
Naboo circles around Betelgeuse at the 12220.902 AU
$
```
### Notions
[Polymorphism](https://docs.oracle.com/javase/tutorial/java/IandI/polymorphism.html)