namespace Project
{
/// <summary>
/// 教室类,只有一个门
/// </summary>
class ClassRoom
{
public ClassRoom(string roomNum)
{
this.roomNum = roomNum;
}
private string roomNum;
// 临时集合
private Stack callStuList;
// 学生(集合) 字段
private List<Student> stuList ;
// 对外属性
public List<Student> StuList
{
get
{
return stuList;
}
set
{
stuList = value;
}
}
//老师
private Teacher classTeacher;
public Teacher ClassTeacher
{
get
{
return classTeacher;
}
set
{
classTeacher = value;
}
}
/// <summary>
/// 点名,把所有学生的信息输出
/// var 让编辑器去帮助我们推导出变量类型
/// 随机点名
/// </summary>
public void CallStuentNames()
{
//清空 已经点过的同学集合
//calledStuList.Clear();
//Console.WriteLine(classTeacher);
//Console.WriteLine("开始随机点名:");
Random rand = new Random();
通过已有的集合构造一个新的集合
callStuList = new Stack(StuList);
//while (StuList.Count > 0)
//{
// Console.WriteLine(StuList.Pop());
//}
}
public void AddStudentsFromArrayList(ArrayList array)
{
//if(StuList == null)
//{
// StuList = new Stack();
//}
//foreach (var item in array)
//{
// StuList.Push(item);
//}
}
const int MAX = 3;
/// <summary>
/// 添加学生到教室
/// </summary>
/// <param name="stu"></param>
public void AddStudent(Student stu)
{
//if(stuList == null)
//{
// // 通过throw 关键字抛出异常
// throw new Exception("学生列表为NULL");
//}
if (stuList == null)
{
stuList = new List<Student>();
}
if(stuList.Count >= MAX)
{
throw new ClassFullException(MAX);
}
stuList.Add(stu);
// 将学生的操作和老师的事件绑定(绑定操作)
classTeacher.ShowMeEevent += stu.PrintStudentInfo;
}
}
}