dm6801

171123 - Class 07 - Adult

Nov 26th, 2017
41
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.13 KB | None | 0 0
  1. package myApp;
  2.  
  3. public class Adult {
  4.    
  5.     /* Properties */
  6.     private String name, profession;
  7.     private double height;
  8.    
  9.    
  10.     /* Get, Set Methods */
  11.     public String getName() {
  12.         return this.name;
  13.     }
  14.     public void setName(String name) {
  15.         this.name = name;
  16.     }
  17.    
  18.     public String getProfession() {
  19.         return this.profession;
  20.     }
  21.     public void setProfession(String profession) {
  22.         this.profession = profession;
  23.     }
  24.    
  25.     public double getHeight() {
  26.         return this.height;
  27.     }
  28.     public void setHeight(double height) {
  29.         this.height = height;
  30.     }
  31.    
  32.    
  33.     /* Constructors */
  34.     public Adult(String name, double height, String profession) {
  35.         this.name = name;
  36.         this.height = height;
  37.         this.profession = profession;
  38.     }
  39.     public Adult(String name, double height) {
  40.         this(name, height, "");
  41.     }
  42.     public Adult(Adult adultObject) {
  43.         this.name = adultObject.name;
  44.         this.profession = adultObject.profession;
  45.         this.height = adultObject.height;
  46.     }
  47.    
  48.    
  49.     /* Methods */
  50.     public void showSummary() {
  51.         System.out.printf("(%s) %s is %.2fcm%s%n",
  52.                             this, name, height, profession.equals("")?"":(", and is a "+profession));
  53.     }
  54.    
  55.    
  56.    
  57.    
  58. }
Add Comment
Please, Sign In to add comment