2019-09-13 18:50:57 +03:00
|
|
|
## Constraining Visibility (#1)
|
|
|
|
|
2019-10-10 18:58:14 +03:00
|
|
|
Create an `Alien` class with a constructor that initializes `public val name`
|
|
|
|
and `public val species` properties. Add a `private var planet` property
|
2019-09-13 18:50:57 +03:00
|
|
|
initialized by the constructor. `planet` can be modified with the
|
|
|
|
`movePlanet()` member function. `movePlanet()` takes the planet the `Alien` is
|
2020-04-28 23:39:10 +03:00
|
|
|
moving *to* as its parameter. All properties and parameters are of type
|
|
|
|
`String`. Override `toString()` to return the `name`, `species` and `planet` in
|
|
|
|
the format `"Alien $name, $species: $planet"`.
|
2019-09-13 18:50:57 +03:00
|
|
|
|
|
|
|
In `main()`, create two `Alien`s and move them from an origin `planet` to a
|
2020-04-28 23:39:10 +03:00
|
|
|
destination `planet`, testing them using `toString()` along with the data:
|
2019-09-13 18:50:57 +03:00
|
|
|
|
2019-10-10 18:58:14 +03:00
|
|
|
| `name` | `species` | Origin | Destination |
|
|
|
|
|-----------|------------|-------------|-------------|
|
|
|
|
| Arthricia | Cat Person | PurgePlanet | Earth C-137 |
|
|
|
|
| Dale | Giant | Gearworld | Parblesnops |
|
2019-09-13 18:50:57 +03:00
|
|
|
|
2019-10-10 18:58:14 +03:00
|
|
|
Note that a `val` property is safe to access directly as a `public` property
|
2019-09-13 18:50:57 +03:00
|
|
|
rather than making it `private`.
|