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.

60 lines
2.4 KiB

## StarMass
### Instructions
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
For this last exercise, let's compute the mass of all objects in a galaxy, according to their type.
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
Firstly, let's add a mass property (it will be an integer) to all objects. I let you guess the class where to add it ;)
You need to add the getter and setter for this property too. You will need to add a mass argument to all the constructors.
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
In the `Galaxy` class, we will add a new method `computeMassRepartition` which returns a Map. This map will have as keys the Strings `Star`, `Planet` or `Other`. The values will be the sum of the mass of the objects by their type.
### Usage
Here is a possible ExerciseRunner.java to test your function :
```java
public class ExerciseRunner {
public static void main(String[] args) {
Galaxy galaxy = new Galaxy();
CelestialObject charron = new CelestialObject("Charron", -123.12, 392.238, 32.31, 157);
CelestialObject lune = new CelestialObject("Lune", 3928.32, 327.239, -12.92, 3987);
Star betelgeuse = new Star("Betelgeuse", 128.23, -12.82, 32.328, 1289.3, 538595);
Star altair = new Star("Betelgeuse", 43894.34, -324.43, 9438.23, 123.54, 137273);
Star bellatrix = new Star("Bellatrix", 584.34, 2103.32, -102.43, 413.2, 5483724);
Planet naboo = new Planet("Naboo", 17.4389, 8349.1, 8943.92, betelgeuse, 32454);
Planet tatooine = new Planet("Tatooine", 17.4389, 8349.1, 8943.92, betelgeuse, 2345);
Planet mercure = new Planet("Mercure", 17.4389, 8349.1, 8943.92, altair, 19438);
Planet venus = new Planet("Venus", 17.4389, 8349.1, 8943.92, altair, 9283);
Planet mars = new Planet("Mars", 17.4389, 8349.1, 8943.92, altair, 2183);
galaxy.addCelestialObject(lune);
galaxy.addCelestialObject(charron);
galaxy.addCelestialObject(mars);
galaxy.addCelestialObject(mercure);
galaxy.addCelestialObject(tatooine);
galaxy.addCelestialObject(altair);
galaxy.addCelestialObject(venus);
galaxy.addCelestialObject(betelgeuse);
galaxy.addCelestialObject(naboo);
galaxy.addCelestialObject(bellatrix);
System.out.println(galaxy.computeMassRepartition().toString());
}
}
```
and its output :
```shell
$ javac *.java -d build
$ java -cp build ExerciseRunner
{Star=6159592, Planet=65703, Other=4144}
$
```
### Notions
[InstanceOf](https://www.baeldung.com/java-instanceof)