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 EasterGoodiesdouble weight, double volume
Weight weight;
Volume volume;
public class ChocEgg : EasterGoodies
public ChocEgg : base
public class ChocBunny : EasterGoodies
public ChocBunny : base
public class Crackers : EasterGoodies
public Crackers : base
public class Water : EasterGoodies
public Water : base
public class HardCandy : EasterGoodies
public HardCandy : base
public class SodaCan : EasterGoodies
public SodaCan : base
public class Basket
private List items new List;
private double totalWeight ;
private double totalVolume ;
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 Basketint itemLimit, double weightLimit, double volumeLimit
ItemLimit itemLimit;
WeightLimit weightLimit;
VolumeLimit volumeLimit;
public bool AddEasterGoodies item
if CurrentItemCount ItemLimit CurrentWeight item.Weight WeightLimit CurrentVolume item.Volume VolumeLimit
return false;
items.Additem;
totalWeight item.Weight;
totalVolume item.Volume;
return true;
class Program
static void Mainstring args
Basket basket new Basket;
Console.WriteLineMenu:;
Console.WriteLine ChocEgg";
Console.WriteLine ChocBunny";
Console.WriteLine Crackers";
Console.WriteLine Water";
Console.WriteLine HardCandy";
Console.WriteLine SodaCan";
Console.WriteLine Exit";
while true
Console.WriteEnter your choice: ;
int choice;
if int.TryParseConsoleReadLine out choice
Console.WriteLineInvalid choice. Please enter a number from the menu.";
continue;
switch choice
case :
Console.WriteLineExiting;
return;
case :
TryAddItemnew ChocEgg;
break;
case :
TryAddItemnew ChocBunny;
break;
case :
TryAddItemnew Crackers;
break;
case :
TryAddItemnew Water;
break;
case :
TryAddItemnew HardCandy;
break;
case :
TryAddItemnew SodaCan;
break;
default:
Console.WriteLineInvalid choice. Please enter a number from the menu.";
break;
void TryAddItemEasterGoodies item
if basketAdditem
Console.WriteLineItem added.";
else
Console.WriteLineCant add item. Basket is full or the weightvolume limit exceeded.";
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
