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.

56 lines
1.3 KiB

## StarConstructors
### Instructions
We will now add two 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
* The default one, with no parameters which initialises the properties with following values :
* `x` : `0.0`
* `y` : `0.0`
* `z` : `0.0`
* `name` : `"Soleil"`
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
* The second one takes four parameters and sets the values of `name`, `x`, `y` and `z`.
### Usage
Here is a possible ExerciseRunner.java to test your function :
```java
public class ExerciseRunner {
public static void main(String[] args) {
CelestialObject defaultStar = new CelestialObject();
System.out.println(defaultStar.x);
System.out.println(defaultStar.y);
System.out.println(defaultStar.z);
System.out.println(defaultStar.name);
CelestialObject earth = new CelestialObject("Terre", 0.43, 0.98, 1.43);
System.out.println(earth.x);
System.out.println(earth.y);
System.out.println(earth.z);
System.out.println(earth.name);
}
}
```
and its output :
```shell
$ javac *.java -d build
$ java -cp build ExerciseRunner
0.0
0.0
0.0
Soleil
0.43
0.98
1.43
Terre
$
```
### Notions
[Class](https://docs.oracle.com/javase/tutorial/java/javaOO/classdecl.html)
[Property](https://docs.oracle.com/javase/tutorial/java/javaOO/variables.html)