<?

	class Student
	{
		private $name;
		private $id;
		private $phone;
		
		private $grades;
		private $gpa;
		
		public function __construct($name, $id, $phone)
		{
			$this->name = $name;
			$this->id = $id;
			$this->phone = $phone;
			
			$this->grades = array();
			$this->CalculateGPA();
		}
		
		public function getName()
		{
			return $this->name;
		}
		
		public function getId()
		{
			return $this->id;
		}
		
		public function getPhone()
		{
			return $this->phone;
		}
		
		public function GetGrades()
		{
			return $this->grades;
		}
		
		public function GetGPA()
		{
			return $this->gpa;
		}
		
		public function AddGrade($grade)
		{
			$this->grades[] = $grade;
			$this->CalculateGPA();
		}
		
		public function ChangeGrade($index, $grade)
		{
			if($index < 0 || $index >= count($this->grades))
				return;
				
			$this->grades[$index] = $grade;
			$this->CalculateGPA();
		}
		
		private function CalculateGPA()
		{
			if(count($this->grades) == 0)
			{
				$this->gpa = -1;
				return;
			}
		
			$sum = 0;
			$tot = 0;
			
			foreach($this->grades as $g)
			{
				$sum = $sum + $g;
				$tot = $tot + 1;			
			}
			
			$this->gpa = ($sum / $tot)/100 * 4.0;
		}
	}

?>