Question
C sharp please. Create a class named Backpack. The Backpack class should have three private fields named mainPocketWeight, leftPocketWeight, and rightPocketWeight of type double. Write
C sharp please.
Create a class named Backpack. The Backpack class should have three private fields named mainPocketWeight, leftPocketWeight, and rightPocketWeight of type double.
Write a method named InsertItemsInMainPocket that receives a parameter of type double that represents the weight of the items to be inserted. The method should increment the mainPocketWeight field so that it represents the weight of the items inserted. The main pocket is allowed to carry at most ten pounds. The method should return true if the items can be inserted in the pocket, or false if the items would cause the weight to exceed the weight limit.
Create methods named InsertItemsInRightPocket and InsertItemsInLeftPocket that increment the appropriate field. The left and right pockets are allowed to carry at most five pounds. The methods should return true if the items can be inserted in the pocket, or false if the items would cause the weight to exceed the weight limit.
Create a method named GetTotalWeight that returns a value that represents the weight of all items in the backpack.
Write a method named RemoveItemsFromMainPocket that receives a parameter of type double that represents the weight of the items to be removed from the mainPocketWeight field. Based on the parameter value, the method should decrement the mainPocketWeight field. The method should return true if the weight of the items to be removed does not exceed the weight of the items in the pocket, or false otherwise. Implement the same type of method for the right and left pockets.
Test the class by allocating a Backpack object, inserting items, and calling the GetTotalWeight method.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started