Difference between revisions of "QueueOfTiles Purpose"

From TRCCompSci - AQA Computer Science
Jump to: navigation, search
(Added code and a brief summery)
 
 
Line 1: Line 1:
 
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.
 
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.
 +
 +
The programmer could have used the built in Queue Abstract data type, but has instead created a Queue using a class. Remember abstract means it is not defined by its implementation, but by the operations  it carries out.
  
 
=Code=
 
=Code=

Latest revision as of 13:02, 14 November 2017

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.

The programmer could have used the built in Queue Abstract data type, but has instead created a Queue using a class. Remember abstract means it is not defined by its implementation, but by the operations it carries out.

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
		}