Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Genomes And Databases On The Internet A Practical Guide To Functions And Applications

Authors: Paul Rangel

1st Edition

189848631X, 978-1898486312

More Books

Students also viewed these Databases questions

Question

How does selection differ from recruitment ?

Answered: 1 week ago