- Properly Encapsulate The Following Class Use Traditional Getters And Setters Accessors And Mutators Or Properties En 1 (253.17 KiB) Viewed 70 times
Properly encapsulate the following class. Use traditional getters and setters (accessors and mutators) or Properties. En
-
- Site Admin
- Posts: 899603
- Joined: Mon Aug 02, 2021 8:13 am
Properly encapsulate the following class. Use traditional getters and setters (accessors and mutators) or Properties. En
Properly encapsulate the following class. Use traditional getters and setters (accessors and mutators) or Properties. Ensure that the class cannot be put into an invalid state (no name and/or age < 0). public class Person { public string name; public int age; public Speed walkingSpeed; public Person(string name, int age, Speed walkingSpeed) { } ENCUEN RUCI this.name = (name == "") ? "unnamed one" : name; this.age = (age < 0) ? 0: age; this.walkingSpeed = walkingSpeed; public enum Speed { Slow, Medium, Fast };