eranseg

Adult

Aug 25th, 2019
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.82 KB | None | 0 0
  1. /////////////////////// Adult Class ///////////////////////
  2.  
  3. public class Adult {
  4.  
  5.     //Adult properties
  6.     private String name;
  7.     private String professional;
  8.     private double height;
  9.  
  10.     //Full properties constructor
  11.     public Adult(String name, String professional, double height) {
  12.         this.name = name;
  13.         setProfessional(professional);
  14.         setHeight(height);
  15.     }
  16.  
  17.     //Partial constructor
  18.     public Adult(String name, double height) {
  19.         this(name,null, height);
  20.     }
  21.  
  22.     public Adult(Adult adult) {
  23.         this.name = adult.name;
  24.         this.professional = adult.professional;
  25.         this.height = adult.height;
  26.     }
  27.  
  28.     public String getName() {
  29.         return name;
  30.     }
  31.  
  32.     public String getProfessional() {
  33.         return professional;
  34.     }
  35.  
  36.     public void setProfessional(String professional) {
  37.         this.professional = professional;
  38.     }
  39.  
  40.     public double getHeight() {
  41.         return height;
  42.     }
  43.  
  44.     public void setHeight(double height) {
  45.         if(height < 0.6 || height > 3.0) {
  46.             this.height = 1.5;
  47.             System.out.println("No human can be at " + height + " height! The height is adjusted to 1.5 meters.");
  48.         } else {
  49.             this.height = height;
  50.         }
  51.     }
  52.  
  53.     public void printDetails() {
  54.         System.out.println(name + " is " + height + " meters high and his professional is " + professional + ".");
  55.     }
  56. }
  57.  
  58. /////////////////////////////// Main Class //////////////////////////////////
  59.  
  60. public class AdultView {
  61.     public static void main(String[] args) {
  62.         Adult p1 = new Adult("Eran", "Project Manager", 1.84);
  63.         Adult p2 = new Adult("Yossi", 1.78);
  64.         Adult p3 = new Adult(p1);
  65.         p1.printDetails();
  66.         p2.printDetails();
  67.         p3.printDetails();
  68.     }
  69. }
Add Comment
Please, Sign In to add comment