using System.Collections.Generic;
public abstract class Fruit
public string mDisplayName { get; protected set; } = string.Empty;
public Color mColor { get; protected set; } = Color.Gray;
public double mWeight { get; protected set; } = 0.0;
public double mPrice { get; protected set; } = 0.0;
public abstract string GetDescription();
protected string GetColorString()
return Enum.GetName(typeof(Color), mColor);
protected string GetPriceWeightString()
return $"${mPrice.ToString("0.00")}, {mWeight.ToString("0.00")} lbs each";
public class Apple : Fruit
public string mAppleSubtype { get; set; } = "Honeycrisp";
public override string GetDescription()
return $"Beatiful {GetColorString()} {mDisplayName}s, of the {mAppleSubtype} variety.\n({GetPriceWeightString()})";
public class Banana : Fruit
public double mLength { get; set; } = 8.5;
public override string GetDescription()
return $"Tropical {GetColorString()} {mDisplayName}s, {mLength} inches long.\n({GetPriceWeightString()})";
public class Pear : Fruit
public DateTime mPickedDateTime { get; set; } = new DateTime(2023, 04, 18);
public override string GetDescription()
return $"Juicy {GetColorString()} {mDisplayName}s, picked on {mPickedDateTime.ToString("D")}.\n({GetPriceWeightString()})";
public class Orange : Fruit
public double mRadius { get; set; } = 2.3;
public override string GetDescription()
return $"Massive {GetColorString()} {mDisplayName}s, with a {mRadius} inch radius!\n({GetPriceWeightString()})";
public class Grape : Fruit
public int mNumPerVine { get; set; } = 16;
public override string GetDescription()
return $"Gorgeous {GetColorString()} {mDisplayName}s on the vine, {mNumPerVine} per vine.\n({GetPriceWeightString()})";
public class FruitBasket : List<Fruit>
return base.Count >= base.Capacity;
public bool AddFruit(Fruit argFruit, int argNumFruits)
if (base.Count + argNumFruits > base.Capacity)
base.AddRange(Enumerable.Repeat(argFruit, argNumFruits));
public int GetCurrentCapacity()
return base.Capacity - base.Count;
public double GetTotalWeight()
foreach (Fruit lFruit in this)
lTotal += lFruit.mWeight;
public double GetTotalPrice()
foreach (Fruit lFruit in this)
public static void Main()
List<Fruit> lFruitList = new List<Fruit>()
FruitBasket lFruitBasket = new FruitBasket();
Console.WriteLine($"Welcome to the fruit stand! Follow the prompts below to fill up your shopping basket with fruits.\n");
foreach (Fruit lFruit in lFruitList)
lIsDoneWithFruit = false;
Console.WriteLine($"\n{lFruit.GetDescription()}\n");
while (!lIsDoneWithFruit)
Console.WriteLine($"Would you like to add {lFruit.mDisplayName}s to your basket? (Y/N)\n");
lResponse = Console.ReadLine().ToLower();
Console.WriteLine($"\nHow many {lFruit.mDisplayName}s would you like?\n");
lResponse = Console.ReadLine();
if (Int32.TryParse(lResponse, out lNumFruits))
Console.WriteLine("\nPlease enter a number greater than 0. (limit 10 fruits per basket)\n");
else if (lFruitBasket.AddFruit(lFruit, lNumFruits))
Console.WriteLine($"\nAdded {lNumFruits} {lFruit.mDisplayName}{(lNumFruits > 1 ? "s" : "")} to your basket. You have room for {lFruitBasket.GetCurrentCapacity()} more fruits.\n");
Console.WriteLine($"\nToo many {lFruit.mDisplayName}s! You only have room for {lFruitBasket.GetCurrentCapacity()} more fruits.\n");
Console.WriteLine("\nPlease enter a number greater than 0. (limit 10 fruits per basket)\n");
Console.WriteLine("\nInvalid response.\n");
if (lFruitBasket.IsFull())
Console.WriteLine($"\nThank you for shopping with us!\n\nTotal weight of fruits: {lFruitBasket.GetTotalWeight().ToString("0.00")} lbs\nTotal price of fruits: ${lFruitBasket.GetTotalPrice().ToString("0.00")}");