Question: C# PROGRAMMING QUESTION: Create a class library with two classes in it: DataItem and DataStore . The class diagrams are shown below. Make sure that

C# PROGRAMMING QUESTION:

Create a class library with two classes in it: DataItem and DataStore.

The class diagrams are shown below. Make sure that your classes conform to them exactly.

Create DataItem class.

Create the following class members:

  • Content is an auto implemented property representing the content of data item
  • Key is the auto implemented property representing the unique key of the data item. It is assigned by the date store when the item is added to the data store.
  • ToString() method that generates the string with information about the data item. Make sure that your output matches the one that is provided.

Create DataStore class.

This class can only have one instance.

Create the following class members:

  • currentKey is a private field representing the last key that is assigned to a data item.
  • data is read only field that is a list of DataItem objects that are in the data store.
  • instance is a private class field representing the reference to the data store instance that is created.
  • maxCapacity is a private field representing maximum number of data items that the store can hold.
  • CreateStore() is a class method that returns the reference to the created DataStore object. It takes one parameter that represent maximum capacity of the data store. If a data store has not already been created it creates the instance, otherwise it sets the existing data store capacity to a new capacity value provided by the parameter.
  • A private constructor that takes 1 parameter: capacity and assigns the values to appropriates member.
  • AddData() method has one parameter: string representing the content of the data item that needs to be added to the data store. The method creates and returns a DataItem object containing the provided content and the new unique key. The method will add the newly created DataItem to the list of items in the store. If the data store is already at capacity, it throws exception with message: "Maximum number reached. Remove item before adding new one".
  • FindItem() method has one parameter representing the key of the data item to be found. It returns null if the item with provided key is not found.
  • RemoveItem() method has one parameter representing the key of the data item to be removed. It removes item with the provided key. Make sure there is no duplication of code.

Create the console application that will have test harness. Program class is the only class in the console application. You are provided with the content of the Program.cs file in the console application. You must use it exactly as is.

using DataStoreLib;

using System;

namespace DataStoreDemo

{

class Program

{

static void Main(string[] args)

{

DataStore dataStore = DataStore.CreateStore(3);

DataItem dataItem;

dataItem = dataStore.AddData("First element");

Console.WriteLine(dataItem);

dataItem = dataStore.AddData("Second element");

Console.WriteLine(dataItem);

dataItem = dataStore.AddData("Third element");

Console.WriteLine(dataItem);

try

{

dataItem = dataStore.AddData("First element");

Console.WriteLine(dataItem);

}

catch (Exception ex)

{

Console.WriteLine(ex.Message);

}

dataItem = DataStore.FindItem(4);

if (dataItem == null)

{

Console.WriteLine("Data item is not found");

}

else

{

Console.WriteLine(dataItem);

}

Console.WriteLine(DataStore.FindItem(2));

dataStore.RemoveItem(3);

DataStore dataStoreMoreCapacity = DataStore.CreateStore(4);

dataItem = dataStoreMoreCapacity.AddData("Fourth element");

Console.WriteLine(dataItem);

dataItem = dataStore.AddData("Fifth element");

Console.WriteLine(dataItem);

try

{

dataItem = dataStoreMoreCapacity.AddData("Sixth element");

Console.WriteLine(dataItem);

}

catch (Exception ex)

{

Console.WriteLine(ex.Message);

}

}

}

}

The output must be exactly as provided bellow:

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!