Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package class170706;
- public class Person {
- // properties
- private String name; // person name, 2 letters at least
- private int height; // person height in cm, positive value
- private double weight; // person weight in kgm, positive value
- // get person name
- public String getName() {
- return name;
- }
- // set person name
- public boolean setName(String name) {
- // if argument is invalid
- if (name.length() < 2) {
- // no changes, return false
- return false;
- }
- // update person name
- this.name = name;
- // return true
- return true;
- }
- // get person height (cm)
- public int getHeight() {
- return height;
- }
- // set person height in cm, should be positive value
- public boolean setHeight(int height) {
- // if invalid argument
- if (height <= 0) {
- // no changes to person, return false
- return false;
- }
- // update person height and return true
- this.height = height;
- return true;
- }
- // get person weight (in kg)
- public double getWeight() {
- return weight;
- }
- // set person weight in kg, should be positive
- public boolean setWeight(double weight) {
- // if invalid argument
- if (weight <= 0) {
- // return false , no changes
- return false;
- }
- // update weight and return true
- this.weight = weight;
- return true;
- }
- @Override
- public String toString() {
- return String.format(
- "Person [name=%s, height=%d (cm), weight=%1f (kg)]", this.name,
- this.height, this.weight);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement