Latest From our Blog

Hackerrank 30 Days Of Code – Day 4: Class Vs. Instance in PHP

Hackerrank 30 Days Of Code – Day 4: Class Vs. Instance Solution

 


 age=$initialAge;            
       
       }


    }
   public  function amIOld(){
            // Do some computations in here and print out the correct statement to the console 
if($this ->age>= 18) {printf("You are old.\n");}
else if($this ->age>=13 && $this ->age<18){printf("You are a teenager.\n");}
else {printf("You are young.\n");}
    }
   public  function yearPasses(){
          // Increment the age of the person in here
       
$this ->age=$this ->age+1;
     }     
}
$T = intval(fgets(STDIN));
 for($i=0;$i<$T;$i++){
     $age=intval(fgets(STDIN));
     $p=new Person($age);
     $p->amIOld();
     for($j=0;$j<3;$j++){
         $p->yearPasses();
     }
     $p->amIOld();
     echo "\n";
         
 }
?>

 

 

 

COMMENTS

Log In To Reply