44 lines
1.0 KiB
PHP
44 lines
1.0 KiB
PHP
<?php
|
|
class Etudiant {
|
|
private $nom;
|
|
private $prenom;
|
|
private $age;
|
|
|
|
public function __construct($nom, $prenom, $age) {
|
|
$this->nom = $nom;
|
|
$this->prenom = $prenom;
|
|
$this->age = $age;
|
|
}
|
|
|
|
public function getNom() {
|
|
return $this->nom;
|
|
}
|
|
|
|
public function getPrenom() {
|
|
return $this->prenom;
|
|
}
|
|
|
|
public function getAge() {
|
|
return $this->age;
|
|
}
|
|
|
|
public function setNom($nom) {
|
|
$this->nom = $nom;
|
|
}
|
|
|
|
public function setPrenom($prenom) {
|
|
$this->prenom = $prenom;
|
|
}
|
|
|
|
public function setAge($age) {
|
|
if ($age > 0) {
|
|
$this->age = $age;
|
|
} else {
|
|
throw new Exception("L'âge doit être un nombre positif.");
|
|
}
|
|
}
|
|
|
|
public function afficherInfo() {
|
|
return "Nom: " . $this->nom . ", Prénom: " . $this->prenom . ", Âge: " . $this->age;
|
|
}
|
|
} |