Create an C# application named TestClassifiedAd that instantiates and displays at least two ClassifiedAd objects. A ClassifiedAd has fields for a Category (For example, Used Cars and Help Wanted), a number of Words, and a price. Include properties that contain get and set accessors for the category and number of words, but only a get accessor for the price. The price is calculated at nine cents per word. Note: Your output should be formatted as: The classified ad with 100 words in category Used Cars costs $9.00 The classified ad with 60 words in category Help Wanted costs $5.40 In order to prepend the $ to currency values, the program will need to use the CultureInfo.GetCultureInfo method. In order to do this, include the statement using System.Globalization; at the top of your program and format the output statements as follows: WriteLine("This is an example: {0}", value.ToString("C", CultureInfo.GetCultureInfo("en-US"))); Class executes correctly 0 out of 1 checks passed. Review the results below for more details. Checks Unit TestIncomplete ClassifiedAd class test Build Status Build Failed Build Output Compilation failed: 4 error(s), 0 warnings NtTest8c424fdb.cs(15,22): error CS1061: Type `ClassifiedAd' does not contain a definition for `Words' and no extension method `Words' of type `ClassifiedAd' could be found. Are you missing an assembly reference? TestClassifiedAd.cs(21,7): (Location of the symbol related to previous error) NtTest8c424fdb.cs(17,24): error CS1061: Type `ClassifiedAd' does not contain a definition for `Words' and no extension method `Words' of type `ClassifiedAd' could be found. Are you missing an assembly reference? TestClassifiedAd.cs(21,7): (Location of the symbol related to previous error) NtTest8c424fdb.cs(20,44): error CS1061: Type `ClassifiedAd' does not contain a definition for `Words' and no extension method `Words' of type `ClassifiedAd' could be found. Are you missing an assembly reference? TestClassifiedAd.cs(21,7): (Location of the symbol related to previous error) NtTest8c424fdb.cs(22,44): error CS1061: Type `ClassifiedAd' does not contain a definition for `Words' and no extension method `Words' of type `ClassifiedAd' could be found. Are you missing an assembly reference? TestClassifiedAd.cs(21,7): (Location of the symbol related to previous error) Test Contents [TestFixture] public class ClassifiedAdClassTest { [Test] public void ClassifiedAdTest() { ClassifiedAd myClassifiedAd = new ClassifiedAd(); ClassifiedAd yourClassifiedAd = new ClassifiedAd(); myClassifiedAd.Category = "Used cars"; myClassifiedAd.Words = 100; yourClassifiedAd.Category = "Help wanted"; yourClassifiedAd.Words = 60; Assert.AreEqual("Used cars", myClassifiedAd.Category); Assert.AreEqual(100, myClassifiedAd.Words); Assert.AreEqual("Help wanted", yourClassifiedAd.Category); Assert.AreEqual(60, yourClassifiedAd.Words); } } 10.00 out of 10.00 Program output correctly 1 out of 1 checks passed. Great work! Checks Test CaseComplete Output matches desired format Input Output The classified ad with 100 words in category Used Cars costs $9.00 The classified ad with 60 words in category Help Wanted costs $5.40
using System.Globalization;
using static System.Console;
public class TestClassifiedAd
{
public static void Main()
{
ClassifiedAd ad1 = new ClassifiedAd();
ad1.Category = "Used Cars";
ad1.NumWords = 100;
ClassifiedAd ad2 = new ClassifiedAd();
ad2.Category = "Help Wanted";
ad2.NumWords = 60;
WriteLine("The classified ad with {0} words in category {1} costs {2}", ad1.NumWords, ad1.Category, ad1.Price.ToString("C", CultureInfo.GetCultureInfo("en-US")));
WriteLine("The classified ad with {0} words in category {1} costs {2}", ad2.NumWords, ad2.Category, ad2.Price.ToString("C", CultureInfo.GetCultureInfo("en-US")));
}
}
class ClassifiedAd
{
public string Category { get; set; }
public int NumWords { get; set; }
public double Price
{
get { return NumWords * 0.09; }
}
}