
Head First C# Code: Chapter 6
Bee Management System 1
Worker.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace __Bee_Management_System
{
public class Worker
{
public Worker(string[] jobsICanDo)
{
this.jobsICanDo = jobsICanDo;
}
private string currentJob = "";
public string CurrentJob
{
get
{
return currentJob;
}
}
private string[] jobsICanDo;
private int shiftsToWork;
private int shiftsWorked;
public int ShiftsLeft
{
get
{
return shiftsToWork - shiftsWorked;
}
}
public bool DoThisJob(string job, int numberOfShifts)
{
if (!String.IsNullOrEmpty(currentJob))
return false;
for (int i = 0; i < jobsICanDo.Length; i++)
if (jobsICanDo[i] == job)
{
currentJob = job;
this.shiftsToWork = numberOfShifts;
shiftsWorked = 0;
return true;
}
return false;
}
public bool WorkOneShift()
{
if (String.IsNullOrEmpty(currentJob))
return false;
shiftsWorked++;
if (shiftsWorked > shiftsToWork)
{
shiftsWorked = 0;
shiftsToWork = 0;
currentJob = "";
return true;
}
else
return false;
}
}
}