Question: This assignment attempts to model this social phenomenon. It involves an enum and two main classes: Audience, TikTok and TiktokManager. You will load a set

This assignment attempts to model this social phenomenon. It involves an enum and two main classes: Audience, TikTok and TiktokManager. You will load a set of tikoks from a local file into a List collection. You will perform some simple queries on this collection.

The Tikok and the TikokManager classes must be in separate files and must not be in the Program.cs file. The Audience enum may be implemented in the Tiktok.cs file.

The Audience Enum [5marks]

This enum specifies the intended audience for this tiktok. It consists of three constants as shown in the table below:

Audience Enum

Constants

World Group Special

The TikTok Class

The TikTok class consist of ten members that include two static ones (the members decorated with the $ symbol). You will implement this and all of the classes in Visual Studio. A short description of the class members is given below:

TikTok Class

Fields

-$ _ID : int

Properties

+ Originator : string

+ Length : int

+ HashTag : string

+ Audience : Audience

+ Id : string

Methods

+ constructorTikTok(

originator : string,

length : int,

hashTag : string,

audience : Audience)

+ constructorTikok(

id : string,

originator : string,

length : string,

hashTag : string,

audience : string)

+ ToString() : string

+$ Parse(line : string) : TikTok

The $ symbol is used to denote that this member belongs to the type rather than a specific object and you must use the type to access that member.

Fields [5 points]:

1. _ID this private field is a class variable, it represents the number to be used in setting the id of this item.

Properties [15 points]:

All of the properties are readonly and are self-explanatory.

1. Originator this property is a string representing the originator of this tikok. The getter is public and the setter is absent.

2. Length this property is an int representing the length in second recipient of this tikok. The getter is public and the setter is absent.

3. HashTag this property is a string representing the hashtag of this tikok. The getter is public and the setter is absent.

4. Audience this property is a string representing the distribution of this tikok. The getter is public and the setter is absent.

5. Id this property is a string representing the id of this tikok. The getter is public and the setter is absent. This is used to uniquely identify a tikok.

Constructors [10 points]:

1. public TikTok(string originator, int length, string hashTag, Audience audience) This public constructor takes four string parameters. This constructor does the following: [This is an example of constructor overloading]

a. Assigns the arguments to the appropriate properties.

b. Sets the Id property using the class variable _ID.

c. After the Id property is set, the _ID is then incremented so that the next assignment will be unique. (see description of Id above)

2. private TikTok(string id, string originator, int length, string hashTag, Audience audience) This public constructor takes five string parameters. This is called by the static TikTok Parse(string) method. This constructor does the following:

a. Assigns the arguments to the appropriate properties.

Methods [10 points]:

1. public override string ToString() This method overrides the same method of the Object class. It does not take any parameter but return a string representation of itself. You decide on the format for the output.

2. public static TikTok Parse(string line) This is a public class method that takes a string argument and returns a TikTok object. It is used to create a TikTok object when loading the TikToks from a file. The argument represents a single line of input read from the file. This method does the following:

a. Uses the method of the string class is to chunk the input into four strings. The default delimiter for the Split() method is a space, however in this case the delimiter should be a tab. To specify an argument for the Split() method use the following code: Split('\t');

b. Invokes the five arguments constructor. Because all the arguments are string, it is easy to inter-change the order. You need to examine the text file to make sure that you are sending the arguments to the constructor in the required order.

c. Return the result of the above invocation

The TikTokManager Class

This static class consist of five static members. You will also implement this in Visual Studio. A short description of the class members is given below:

TikTokManager

Static Class

Fields

-$ TIKTOKS : List

-$ FILENAME : string

Methods

$ TikTokManager()

+$ Initialize() : void

+$ Show() : void

+$ Show(hashtag : string) : void

+$ Show(length : int) : void

+$ Show(audience : Audience) : void

ALL MEMBERS ARE STATIC!

Fields [5 points]:

1. TIKTOKS this private field is a class variable; it is a collection of all the tiktoks in the system. It is initialized and populated in the static constructor.

2. FILENAME this private field is a class variable; it represents the name of the file that contains all the tiktoks. It is used in the static constructor to read in the tiktoks. You will have to set this to the name of file that has the information about the tiktoks.

Constructor:

1. static TikTokManager() This is the static constructor. It does not require any parameter. This constructor does the following:

[A static constructor does not take any arguments, nor does it require any accessibility modifier. Infact specifying one will raise a compiler error. It is called before any member is accessed and never ever again.]

a. Initialize the TIKTOKS field to a new list of tiktok

b. Opens the file specified by the filename field for reading

c. Using a looping structure it does the following:

i. Reads one line from the file.

ii. Passes this line to the static Parse() method of the TikTok class to create a tiktok object.

iii. The resulting object is added to the tiktok collection.

iv. This is repeated until the input from the file is empty (null).

Methods [:

1. public static void Initialize() This class method it used to facilitate the development of this project. It will not be used in the production code, just while developing. This method does the following: [This will be used to test your code in the event you cannot figure out the file reading part.]

a. Assigns the TIKOKS field

b. Creates about 5 tiktoks objects and add them to the tiktok collection.

2. public static void Show() This is a public class method that does not take any argument that does not return a value. It displays all the tiktoks in the collection. [This is good example of method overloading, i.e. methods with the same name.

3. public static void Show(string tag) This is a public class method that takes a string argument that does not return a value. It displays all the tiktoks with hashTag matching the argument. This comparison must be case in-sensitive.

4. public static void Show(int length) This is a public class method that takes an int argument that does not return a value. It displays all the tiktoks with length greater than the argument.

5. public static void Show(Audience audience) This is a public class method that takes an int argument that does not return a value. It displays all the tiktoks with audience matching the argument.

Testing [20 points] In your test harness (the Main() method in the Program Class), write the code to test all the methods of the TikTokManager class including the Initialize() method.

When testing with the supplied file copy the file to bin\Debug folder.

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!