Home / Expert Answers / Computer Science / create-an-application-in-c-named-testclassifiedad-that-instantiates-and-displays-at-least-two-class-pa664

(Solved): Create an application in C# named TestClassifiedAd that instantiates and displays at least two Class ...



Create an application in C# 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: 10 error(s), 0 warnings

NtTest50a0a0c0.cs(12,7): error CS0246: The type or namespace name `ClassifiedAd' could not be found. Are you missing an assembly reference?
NtTest50a0a0c0.cs(13,7): error CS0246: The type or namespace name `ClassifiedAd' could not be found. Are you missing an assembly reference?
NtTest50a0a0c0.cs(14,7): error CS0841: A local variable `myClassifiedAd' cannot be used before it is declared
NtTest50a0a0c0.cs(15,7): error CS0841: A local variable `myClassifiedAd' cannot be used before it is declared
NtTest50a0a0c0.cs(16,7): error CS0841: A local variable `yourClassifiedAd' cannot be used before it is declared
NtTest50a0a0c0.cs(17,7): error CS0841: A local variable `yourClassifiedAd' cannot be used before it is declared
NtTest50a0a0c0.cs(19,36): error CS0841: A local variable `myClassifiedAd' cannot be used before it is declared
NtTest50a0a0c0.cs(20,29): error CS0841: A local variable `myClassifiedAd' cannot be used before it is declared
NtTest50a0a0c0.cs(21,38): error CS0841: A local variable `yourClassifiedAd' cannot be used before it is declared
NtTest50a0a0c0.cs(22,27): error CS0841: A local variable `yourClassifiedAd' cannot be used before it is declared

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);
   }
}

0.00 out of 10.00

Program output correctly

0 out of 1 checks passed. Review the results below for more details.

Checks

Test CaseIncomplete

Output matches desired format

Input


 

Output

23 45 67
67 45 23

Results

(The classified ad with)\s\d+\s(words in category)\s(\w+\s){1,}(costs\s\$\d\.\d{2})(\r\n|\r|\n)*+(The classified ad with)\s\d+\s(words in category)\s(\w+\s){1,}(costs\s\$\d\.\d{2})

Examples:

using static System.Console;
using System.Globalization;
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; }
    }
}

 

Examples:

using System;

namespace TestClassifiedAd
{
class Program
{
String _category;
int _words;
double _price;


public string category
{
get { return _category; }
set { _category = value; }
}

public int words
{
get { return _words; }
set { _words = value; }
}


public double price
{
get {
return _price;
}
}


public void calcPrice()
{
_price = 9 * _words;
_price /= 100;
}

static void Main(string[] args)
{
Program ad = new Program();

Console.WriteLine("Enter the category of Ad");
ad._category = Console.ReadLine();

Console.WriteLine("Enter the words in Ad");
ad._words = Convert.ToInt32(Console.ReadLine());

ad.calcPrice();


Console.WriteLine("The classified " +
"ad with {0} words in category {1}" +
" costs ${2:0.00}.", ad._words, ad._category, ad._price);


Console.ReadLine();
}
}
}

using System;



class Reverse3 {

//method to reverse the order of three parameters
public static void Reverse(ref int firstVal, ref int middleVal, ref int lastVal){
//storing firstVal in temp
int temp=firstVal;
//assigning lastVal to firstVal
firstVal=lastVal;
//assigning temp to lastVal
lastVal=temp;
//middleVal is unmodified.
}

public static void Main(String[] args) {
//declaring three integers
int firstInt,middleInt,lastInt;
//assigning values
firstInt=23;
middleInt=45;
lastInt=67;
//displaying values. since you didn't mention the format of displaying
//the numbers, I'm just printing the numbers separated by space.
//change it as you need (depends on your unit test)
Console.WriteLine(firstInt+" "+middleInt+" "+lastInt);
//reversing position of numbers
Reverse(ref firstInt,ref middleInt,ref lastInt);
//displaying reversed values.
Console.WriteLine(firstInt+" "+middleInt+" "+lastInt);

}
}

 

Programming Exercise 9-2

Programming Exercise 9-2


We have an Answer from Expert

View Expert Answer

Expert Answer


using static System.Console; using System.Globalization; public class TestClassifiedAd { public static void Main() { ClassifiedAd ad1 = new ClassifiedAd(); ad1.Category = "Used Cars"; ad1.Num
We have an Answer from Expert

Buy This Answer $5

Place Order

We Provide Services Across The Globe