Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /////////////////////// Adult Class ///////////////////////
- public class Adult {
- //Adult properties
- private String name;
- private String professional;
- private double height;
- //Full properties constructor
- public Adult(String name, String professional, double height) {
- this.name = name;
- setProfessional(professional);
- setHeight(height);
- }
- //Partial constructor
- public Adult(String name, double height) {
- this(name,null, height);
- }
- public Adult(Adult adult) {
- this.name = adult.name;
- this.professional = adult.professional;
- this.height = adult.height;
- }
- public String getName() {
- return name;
- }
- public String getProfessional() {
- return professional;
- }
- public void setProfessional(String professional) {
- this.professional = professional;
- }
- public double getHeight() {
- return height;
- }
- public void setHeight(double height) {
- if(height < 0.6 || height > 3.0) {
- this.height = 1.5;
- System.out.println("No human can be at " + height + " height! The height is adjusted to 1.5 meters.");
- } else {
- this.height = height;
- }
- }
- public void printDetails() {
- System.out.println(name + " is " + height + " meters high and his professional is " + professional + ".");
- }
- }
- /////////////////////////////// Main Class //////////////////////////////////
- public class AdultView {
- public static void main(String[] args) {
- Adult p1 = new Adult("Eran", "Project Manager", 1.84);
- Adult p2 = new Adult("Yossi", 1.78);
- Adult p3 = new Adult(p1);
- p1.printDetails();
- p2.printDetails();
- p3.printDetails();
- }
- }
Add Comment
Please, Sign In to add comment