Question: using System; class ClassifiedAd { / / Properties public string Category { get; set; } public int Words { get; set; } public double Price

using System; class ClassifiedAd {// Properties public string Category { get; set; } public int Words { get; set; } public double Price { get; set; }// Constructor public ClassifiedAd(string category, int words){ Category = category; Words = words; // Call the method to calculate and set the initial price CalPrice(); }// Method to calculate and set the ad price public void CalPrice(){// Calculate the price based on the number of words and category if (Category == "Painting"){ Price = Words *0.09; } else if (Category == "Moving"){ Price = Words *0.09+5.00; } else {// Default price if the category is not recognized Price = Words *0.08; }}} class AdApp3{ static void Main(){// Create instances of ClassifiedAd ClassifiedAd ad1= new ClassifiedAd("Painting",120); ClassifiedAd ad2= new ClassifiedAd("Moving",150); // Display information about the first advertisement Console.WriteLine($"What is the category of the first advertisement? {ad1.Category}"); Console.WriteLine($"How many words does it have? {ad1.Words}"); // Display information about the second advertisement Console.WriteLine($"What is the category of the second advertisement? {ad2.Category}"); Console.WriteLine($"How many words does it have? {ad2.Words}"); // Display the calculated prices Console.WriteLine($"The classified ad with {ad1.Words} words in category {ad1.Category} costs ${ad1.Price.ToString("F2")}"); Console.WriteLine($"The classified ad with {ad2.Words} words in category {ad2.Category} costs ${ad2.Price.ToString("F2")}"); // Wait for user input before closing the console window Console.WriteLine("Press any key to continue"); Console.ReadKey(); }}

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 Programming Questions!