Diner.cs
using System.Collections.Generic; // for List
using party.house.rooms.furniture; // for Chair, Table, DiningTable
using party.house.occupants; // for Robot
namespace party.house.rooms
{
class Diner : Room // Diner is a type of Room
{
List<Chair> chairs;
Table table;
public Diner(string name) : base(name) // call base constructor
{
chairs = new List<Chair>();
table = new DiningTable("Dining table");
}
public Diner(string name, Table table) : base(name) // call base constructor
{
chairs = new List<Chair>();
this.table = table;
}
public Table GetTable()
{
return table;
}
public void SetTable(Table table)
{
this.table = table;
}
public void AddChair(Chair chair)
{
chairs.Add(chair);
}
public void RemoveChair(Chair chair)
{
chairs.Remove(chair);
}
public void CleanDiner(Robot r)
{
System.Console.WriteLine(r.ToString() + " cleans the diner");
table.ClearTable();
}
override public string ToString()
{
string message = base.ToString(); // name
message += " is spacious; it has a ";
message += table.Id;
message += " and ";
message += chairs.Count;
if (chairs.Count == 1)
{message += " chair: ";}
else {message += " chairs: ";}
foreach (Chair c in chairs)
{
message += c.Id;
message += ", ";
}
return message;
}
}
}
Comments
Post a Comment