Wednesday, February 9, 2011

Wednesday 2/9/11


<?php
class Employee
{
const CATEGORY_WORKER = 0;
const CATEGORY_SUPERVISOR = 1;
const CATEGORY_MANAGER = 2;

public static $jobTitles = array('regular worker', 'supervisor', 'manager');
public static $payRates = array(5, 8.25, 17.5);

public static function getCategoryInfo($cat)
{
printf("

A %s makes \$%.2f per hour.

\n",
self::$jobTitles[$cat],
self::$payRates[$cat]);
}

public static function calcGrossPay($hours, $cat)
{
return $hours * self::$payRates[$cat];
}
// instance variables

private $firstName;
private $lastName;
private $id;
private $category;

// employee constructor

public function __construct($fname, $lname, $id, $cat=self::CATEGORY_WORKER)
{
$this->firstName = $fname;
$this->lastName = $lname;
$this->id = $id;
$this->category = $cat;
}

public function getFirstName()
{
return $this->firstName;
}

public function getLastName()
{
return $this->lastName;
}

public function getId()
{
return $this->id;
}

public function getCategory()
{
return $this->category;
}

public function setFirstName($fname)
{
$this->firstName = $fname;
}

public function setLastName($lname)
{
$this->lastName = $lname;
}

public function setId($id)
{
$this->id = $id;
}

public function promote()
{
if($this->category < self::CATEGORY_MANAGER)
$this->category++;
}

public function demote()
{
if($this->category < self::CATEGORY_WORKER)
$this->catgory--;
}


public function display()
{
printF(
"

%s %s is Employee #%d, and is a %s making \$%.2f per hour

\n",
$this->getFirstName(),
$this->getLastName(),
$this->getId(),
self::$jobTitles[ $this->getCategory() ],
self::$payRates[ $this->getCategory() ]
);
}



} //end class employee

$bob = new Employee('Bob', 'Smith', 102, Employee::CATEGORY_SUPERVISOR);
$bob->display();
$bob->promote();
$bob->display();



?>

No comments: