Answer to Question #332732 in C# for samit

Question #332732

Make a class named Fruit with a data member to calculate the number of fruits in a basket. Create twoother class named Apples and Mangoes to calculate the number of apples and mangoes in the basket.Print the number of fruits of each type and the total number of fruits in the basket. c#


1
Expert's answer
2022-04-23T09:04:25-0400
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;


class Program
{
    static void Main()
    {
        List<Fruit> basket = new List<Fruit>()
        {
            new Apple(),
            new Apple(),
            new Mango()
        };


        Console.WriteLine($"Count of Fruits: {basket.Count}");
        Console.WriteLine($"Count of Apples: {basket.OfType<Apple>().Count()}");
        Console.WriteLine($"Count of Mangoes: {basket.OfType<Mango>().Count()}");


    }




    class Fruit
    {


    }


    class Apple : Fruit { }
    class Mango: Fruit { }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS