Write a java program to implement the 0-1 Knapsack problem. The program should have a class called Knapsack which will contain the following methods: a). Solve Knapsack b). Print Solution, should print or graphically display the following: Number of items selected Total Value of the items selected List of the items or positions selected c). The program should have a main/driver/test class that can do the following: Receive knapsack Max Weight, I.e., W Receive the number of selectable items Receives the weights for each item Receives the values for each item d). Solves uses the knapsack class to solve and print/display the solution. Requirement: a) The program either an interface to input the required values or allow a user to point to a data file with the values in a specific format to read in. b).Be sure that if a user use user input on a command line or in a GUI checks that values being provided are in range and valid. Additionally, user may want to put limits on values being passed in such as a max capacity or max item list, etc.
Write a java
a). Solve Knapsack
b). Print Solution, should print or graphically display the following:
- Number of items selected
- Total Value of the items selected
- List of the items or positions selected
c). The program should have a main/driver/test class that can do the following:
- Receive knapsack Max Weight, I.e., W
- Receive the number of selectable items
- Receives the weights for each item
- Receives the values for each item
d). Solves uses the knapsack class to solve and print/display the solution.
Requirement:
a) The program either an interface to input the required values or allow a user to point to a data file with the values in a specific format to read in.
b).Be sure that if a user use user input on a command line or in a GUI checks that values being provided are in range and valid. Additionally, user may want to put limits on values being passed in such as a max capacity or max item list, etc.
Unlock instant AI solutions
Tap the button
to generate a solution