Advertisement
JanBarhoum

Untitled

Nov 24th, 2017
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.93 KB | None | 0 0
  1.  
  2.    
  3.     // Create a Adult Class !
  4.  
  5. public class Adult {
  6.  
  7.     private String name,prof;
  8.     private double height ;
  9.     public Adult () {
  10.         System.out.println("Enter name height prof :");
  11.     }
  12.    
  13.     // Create constructor For Three Details!
  14.    
  15.     public Adult(String name,double height , String prof) {
  16.         this.name=name;
  17.         this.height=height;
  18.         this.prof=prof;
  19.     }
  20.  
  21.     public Adult(String name, double height) {
  22.        
  23.         this(name,height,"");
  24.        
  25.     }
  26.     // Create Copy constructor !
  27.    
  28.     public Adult(Adult other ) {
  29.         name=other.name;
  30.         height=other.height;
  31.         prof=other.prof;
  32.     }
  33.    
  34.     //Create Set And Get  FoR DeTails !
  35.    
  36.     public String getName() {
  37.         return name;
  38.     }
  39.  
  40.     public void setName(String name) {
  41.         this.name = name;
  42.     }
  43.  
  44.     public String getProf() {
  45.         return prof;
  46.     }
  47.  
  48.     public void setProf(String prof) {
  49.         this.prof = prof;
  50.     }
  51.  
  52.     public double getHeight() {
  53.         return height;
  54.     }
  55.  
  56.     public void setHeight(double height) {
  57.         this.height = height;
  58.     }
  59.  
  60. //Create An Function That Print All The Details i want !
  61.  
  62. public void printDetails() {
  63.     if (prof.length() > 0 ) {
  64.         System.out.print("name:"+ name + ":height:" + height+ ":prof:"+prof );
  65.     }
  66.     else {
  67.         System.out.println("name:"+name+":height:"+height);
  68.     }
  69. }
  70.  
  71.     }
  72.  
  73.     ##############################################################################################################################
  74.  
  75.  
  76. public class Tester {
  77.  
  78.     public static void main(String[] args) {
  79.        
  80.         // Here I Can Send The Details To The PRINTDETAILS Function That Print All The Details i Sent !
  81.        
  82.        
  83.         Adult p1 = new Adult("Jan",1.80,"OfficeDepot");
  84.        
  85.         Adult p2 = new Adult("Waleed",1.57);
  86.        
  87.         Adult p3 = new Adult ("Hani",1.76,"Hackeru");
  88.        
  89.        
  90.          p1.printDetails();
  91.             System.out.println();
  92.  
  93.            
  94.            
  95.             p2.printDetails();
  96.             System.out.println();
  97.            
  98.            
  99.             p3.printDetails();
  100.             System.out.println();
  101.     }
  102.    
  103.    
  104.    
  105.  
  106. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement