COMPX102-21H

Object-Oriented Programming

Assignment 3

The Knapsack Planner

Imagine you have to spend a year on a remote island, and need to plan which of your belongings to take with you. You have got items with different names, weight (in kg), volume (in cubic centimetres), and value (in dollars and cents). The amount of baggage you can take is restricted to what you can fit in a small number of bags or other containers, each of which can hold only a limited weight and volume of items. 


Exercise 1 (2 marks)

After having read the complete assignment, please identify the two key classes needed to implement the Knapsack Planner. Please draw a UML class diagram showing these classes, their key properties and methods, and the relationships between them.


Exercise 2 (4 marks)

Please create a form with three list boxes or data grid views or similar controls. The first of these (the unpacked list) will display the items not in any container, the second will display the containers, and the third will display the items packed in one of the containers.

Next please write C# code for the classes identified in exercise 1. Initialise lists that contain at least the items and containers mentioned the file knapsack.csv available in Moodle, and make sure that they immediately appear on your form when the program is started. Ensure that all attributes of your objects are displayed, and format them nicely.

Hint. You may hard-code the data into your program, or read it from files. If using files, please make sure your program can be compiled and run from the submission archive. All files needed to run your program must be included in your archive, and accessed through resources or relative path names.


Exercise 3 (10 marks)

In the following, eight additional features of the Knapsack Planner are proposed, each worth two marks. Out of these, you should implement at least five to achieve the ten marks available for this part of the assignment.

a) Provide functionality to edit the lists of items and containers. It should be possible to create and delete items and containers, and modify their simple attributes (name, weight, volume, and value).

b) Provide functionality to display and modify the contents of each container. It should be possible to select a container to display its contents, to add items from the unpacked list to a container, and to remove items from a container.

Note. An item should appear in exactly one place at any time, either in the unpacked list or in a container.

c) Add functionality to empty a container. It should be possible to select a container and move all its contents back to the unpacked list.

d) Enforce the capacity limitations. Before adding items to a container with the functionality b), check whether this causes the container to exceed its maximum weight or volume. If it does, do not add the item to the container and display an explanation instead.

e) For each container, compute and display the total weight, volume, and value of the items it contains. Make sure that this information is displayed on the form for all the containers at all times and updated automatically when data is modified using the editing functionality in a), b), or c).

f) Add labels to your form that display the total weight, volume, and value of all items currently packed in some container. That is, add together the weights, volumes, and values of the container contents from e) and display the combined totals of all containers together. Make sure that this information is displayed at all times and updated automatically when data is modified using the editing functionality in a), b), or c).

g) Provide functionality to load and save all the items and containers together with their packed state to and from files, using the format of the knapsack.csv file in Moodle. The CSV file format consists of two types of lines to distinguish items and containers.

ITEM,<namei>,<weight>,<volume>,<value>

CONTAINER,<name>,<max weight>,<max volume>

Any items listed before the containers should be put in the list of unpacked items, while items listed after a container should be packed in that container.

h) Implement an “Autopack” operation, which automatically packs the available containers to contain items of the maximum total value possible while staying within the weight and volume limits.

Note. The algorithm to find an optimal solution may be difficult to implement. An approximate solution is enough for this exercise.


Exercise 4 (4 marks)

Like the previous assignments, your program will be assessed for its object-oriented design and programming style. To obtain full marks, please choose your classes and instance variables carefully. Make sure you write good object-oriented code, use clear identifier names, follow naming conventions, and make appropriate use of classes and methods. Also please provide a well-designed user interface.


Submission

a)  Please create a .zip archive containing all the files in your C# project directory and submit the archive through Moodle at

http://elearn.waikato.ac.nz/course/view.php?id=54007

b)  Please complete your paper submission, consisting of:

   Your completed and signed cover sheet.

   Your class diagram as specifified in exercise 1.

   A printout of the source code of all .cs files that you have edited.

   A printed screenshot of your running program.

Please put the above items into the box marked COMPX 102H in front of room G.1.15 before the due date.


Verifification

This assignment will be verified during the practical session on Wednesday 27 January 2021 at 13:00 in G.B.13. If you cannot attend on 27 January, please arrange an alternative verification time with the lecturer before the assignment submission deadline.


Submission deadline: Monday, 25 January 2021, 11:00 A.M.