QueueOfTiles Purpose

From TRCCompSci - AQA Computer Science
Revision as of 11:20, 14 November 2017 by Jared (talk | contribs) (Added code and a brief summery)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

This is the entire class called QueueOfTiles, it is created in order to store a lot of methods and data that can be easily accessed throughout the program, the class itself it used to create a queue data type with methods to use the stored data. It uses assumed accessibility so it is a private class which means it cannot be access except in the direct hierarchy. By separating the class, the program is easier to understand.

Code

		class QueueOfTiles
		{
			private List<string> Contents = new List<string>();
			private int Rear;
			private int MaxSize;
			Random Rnd = new Random();

			public QueueOfTiles(int MaxSize)
			{
				this.MaxSize = MaxSize;
				this.Rear = -1;
				for (int Count = 0; Count < this.MaxSize; Count++)
				{
					Contents.Add("");
					this.Add();
				}
			}

			public bool IsEmpty()
			{
				if (this.Rear == -1)
				{
					return true;
				}
				else
				{
					return false;
				}
			}

			public string Remove()
			{
				string Item = "";
				if (IsEmpty())
				{
					return "";
				}
				else
				{
					Item = Contents[0];
					for (int Count = 1; Count < Rear + 1; Count++)
					{
						Contents[Count - 1] = Contents[Count];
					}
					Contents[Rear] = "";
					Rear--;
					return Item;
				}
			}

			public void Add()
			{
				int RandNo = 0;
				if (Rear < MaxSize - 1)
				{
					RandNo = Rnd.Next(0, 26);
					Rear++;
					Contents[Rear] = Convert.ToChar(65 + RandNo).ToString();
				}
			}

			public void Show()
			{
				if (Rear != -1)
				{
					Console.WriteLine();
					Console.Write("The contents of the queue are: ");
					foreach (var item in Contents)
					{
						Console.Write(item);
					}
					Console.WriteLine();
				}
			}
		}

The actual class definition without the methods and variables

		class QueueOfTiles
		{
		//The code
		}