Question: C# language there is an item class, inventory class, and the program class Item class Write a class called Item that contains 2 data members:
C# language
there is an item class, inventory class, and the program class
Item class
Write a class called Item that contains 2 data members: // A string called name and an int called cost. // This class should have a default constructor that sets name to "" // and cost to 0. // It should also have an overloaded constructor. // // Write accessors for each data member. They should be called GetName // GetCost. // Write mutators for each data member. They should be called SetName // and SetCost.
================================================================================================================================================
: inventory class
Define an int called mMaxSize, an array of Items called mItems, and an int called mGold.
: Write a default constructor that assigns the mMaxSize to 10, mItems to a new array of Items with mMaxSize as the size, and mGold to 0.
: Write an accessor for mGold called GetGold.
TODO: Write a mutator for mGold called SetGold.
: Write a method called AddItem that returns a bool and takes an Item parameter. This method should iterate through the mItems array, looking for any Item that is null. If a null Item is found, it should assign that array element to the Item passed in and return true. Otherwise it should return false.
: Write a method called RemoveItem that returns a bool and takes a string parameter. This method should iterate through the mItems array, looking for an Item that has the same name as the parameter. If it finds a match it should set that element of the mItems array to null and return true. Otherwise return false. Do not forget to make sure the element is not null before checking its name.
: Write a method called GetItem that returns an Item and takes a string parameter. This method should iterate through the mItems array, looking for an Item that has the same name as the parameter. If it finds a match it should return that element of the mItems array. Otherwise return null. Do not forget to make sure the element is not null before checking its name.
================================================================================================================================================
program class : Define an Inventory object for the player, an Inventory object for the store and a string for the player's name.
TODO: Ask the user for their name and store their input in the string defined above. If they entered an empty string (e.g. "") assign them a default name.
: Use the Gold mutator to give the player inventory 200 Gold.
TODO: Use the AddItem method to add each item in the PlayerStartingItems array to the player's inventory.
: Use the Gold mutator to give the store inventory 350 Gold.
: Use the AddItem method to add each item in the StoreStartingItems array to the store's inventory. : Call the ShowInventories function and pass in the player's name, the player's inventory and the store's inventory.
Call the DoTransaction procedure and send it the player's name, the player's inventory, the store's inventory and the doBuy variable.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
