assignment help needed

Hello coders, I am looking for solutions in this (not for me) easy assignment OOP:

[php]<?php
class User{

private $id;
private $first_name;
private $last_name;
private $age;

public function __construct($id,$first_name,$last_name,$age){
	 $this->id = $id;
	 $this->first_name = $first_name;
	 $this->last_name = $last_name;
	 $this->age = $age;
}
    public function show() {
      return "Id = " . $this->id . ";Hellooo my name is:" . $this->first_name . " " . $this->last_name . ".I am". $this->age . "years old. I am glad to meet you :-)";
    }
	public function getAge(){
	$this->age = $age;
	}
  }
  

$korisnik = new User(2,"Bojan", "Nikolic", 33);
echo "<br>";
echo $korisnik->show();
echo $korisnik->getAge(15);[/php]

Method “show” should return the value of the properties class name. - Method “getAge” should not have multiple parameters depending on the value of the properties Age that has an object that returns true or false. I dont understand to do this alone…can someone help me with this?

getAge is a verb noun. You are attempting to set the value, not return it.

Thanks, but i dont understand how can I return on simplest way if $age of user are over 18 to show me boolean true, and inverse, if they are not to show me false?

What do you use to check an expression?

I want to use If statement. I know this is not good, but this is what i tried:

$korisnik = new User(2,“Bojan”, “Nikolic”, 33);
echo “
”;
echo $korisnik->show();
return $korisnik->getAge();
$korisnik->age = 33;
if ($korisnik->age <18){
echo “User is over 18 years”;
}
else {
echo “Acces denied”;
}

Should the method return a Boolean?

Yes, boolean.

Then the if statement needs to be in the method. However, there should be an additional method for that verification, because getAge assumes that you will return an integer value.

Ok. Thanks a lot ::slight_smile: I 'll try to do my best…

Sponsor our Newsletter | Privacy Policy | Terms of Service