Question: Write code to solve the following problem: You are going on an easter hunt. You are given a Basket to hold your collected goodies /
Write code to solve the following problem:
You are going on an easter hunt. You are given a Basket to hold your collected goodiesitems
The Basket has three limits: the total number of items it can hold, the weight it can carry, and
the volume it can hold. Each item has a weight and volume, and you must not overload a
Basket by adding too many items, too much weight, or too much volume. There are many item
types that you might add to your inventory, each their own class in the EasterGoodies system.
A chocolate egg has a weight of and a volume of
A chocolate bunny has a weight of and a volume of
A pack of crackers has a weight of and a volume of
Water has a weight of and a volume of
A hard candy pack has a weight of and a volume of
A soda can has a weight of and a volume of
Objectives:
Create an EasterGoodies class that represents any of the different items above. This class
must represent the items weight and volume, which it needs at creation time constructor
Create derived classes for each of the types of items above. Each class should pass the
correct weight and volume to the base class constructor but should be creatable themselves
with a parameterless constructor for example, new HardCany or new ChocBunny
Build a Basket class that can store an array of items. The total number of items, the maximum
weight, and the maximum volume are provided at creation time and cannot change afterward.
Make a public bool AddEasterGoodies item method to Basket class that allows you to add
items of any type to the Baskets contents. This method should fail return false and not modify
the Baskets fields if adding the item would cause it to exceed the Baskets total number of
items, weight, or volume limit
Add properties to Basket that allow it to report the current item count, weight, and volume, and
the limits of each.
Create a program that creates a new Basket and then allow the user to add or attempt to
add items chosen from a menu.
Modify your Homework to 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.
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
