Question: add an abstract method to EasterGoodies class: public abstract string DisplayDetails ( ) ; / / returns the details of a particular basket item Each

add an abstract method to EasterGoodies class:
public abstract string DisplayDetails(); // returns the details of a particular basket item
Each of the subclasses in your project must implement the abstract method.
Your driver program class should show polymorphic behavior by creating several instances from your classes and then referencing to these objects with a base class reference. Your program should print the items that were added to the Basket and the description for each item.
public class EasterGoodies
{
public double Weight {get;}
public double Volume {get;}
public EasterGoodies(double weight, double volume)
{
Weight = weight;
Volume = volume;
}
}
public class ChocEgg : EasterGoodies
{
public ChocEgg() : base(0.1,0.5){}
}
public class ChocBunny : EasterGoodies
{
public ChocBunny() : base(1,2){}
}
public class Crackers : EasterGoodies
{
public Crackers() : base(0.5,2.5){}
}
public class Water : EasterGoodies
{
public Water() : base(2,3){}
}
public class HardCandy : EasterGoodies
{
public HardCandy() : base(6,0.5){}
}
public class SodaCan : EasterGoodies
{
public SodaCan() : base(2.5,3.5){}
}
public class Basket
{
private List items = new List();
private double totalWeight =0;
private double totalVolume =0;
public int ItemLimit {get;}
public double WeightLimit {get;}
public double VolumeLimit {get;}
public int CurrentItemCount => items.Count;
public double CurrentWeight => totalWeight;
public double CurrentVolume => totalVolume;
public Basket(int itemLimit, double weightLimit, double volumeLimit)
{
ItemLimit = itemLimit;
WeightLimit = weightLimit;
VolumeLimit = volumeLimit;
}
public bool Add(EasterGoodies item)
{
if (CurrentItemCount +1> ItemLimit || CurrentWeight + item.Weight > WeightLimit || CurrentVolume + item.Volume > VolumeLimit)
{
return false;
}
items.Add(item);
totalWeight += item.Weight;
totalVolume += item.Volume;
return true;
}
}
class Program
{
static void Main(string[] args)
{
Basket basket = new Basket(5,10,10);
Console.WriteLine("Menu:");
Console.WriteLine("1. ChocEgg");
Console.WriteLine("2. ChocBunny");
Console.WriteLine("3. Crackers");
Console.WriteLine("4. Water");
Console.WriteLine("5. HardCandy");
Console.WriteLine("6. SodaCan");
Console.WriteLine("0. Exit");
while (true)
{
Console.Write("Enter your choice: ");
int choice;
if (!int.TryParse(Console.ReadLine(), out choice))
{
Console.WriteLine("Invalid choice. Please enter a number from the menu.");
continue;
}
switch (choice)
{
case 0:
Console.WriteLine("Exiting...");
return;
case 1:
TryAddItem(new ChocEgg());
break;
case 2:
TryAddItem(new ChocBunny());
break;
case 3:
TryAddItem(new Crackers());
break;
case 4:
TryAddItem(new Water());
break;
case 5:
TryAddItem(new HardCandy());
break;
case 6:
TryAddItem(new SodaCan());
break;
default:
Console.WriteLine("Invalid choice. Please enter a number from the menu.");
break;
}
}
void TryAddItem(EasterGoodies item)
{
if (basket.Add(item))
{
Console.WriteLine("Item added.");
}
else
{
Console.WriteLine("Can't add item. Basket is full or the weight/volume limit exceeded.");
}
}
}
}

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