Knapsack a = new Knapsack(); // creates a Knapsack whose capacity is 15 lbs Knapsack b = new Knapsack(8.8); // creates a Knapsack whose capacity is 8.8 lbsFinally, add a getCapacity() method to the Knapsack class that returns the capacity of the knapsack. Here is the documentation page for Knapsack which you may consult.
KTester2.java tests this new version of Knapsack. Study that program and understand what it is testing. You will know you are done with your revisions if this program compiles and produces the following output:
Weight capacity of this knapsack: 15.00 lbs. The knapsack has 3 items weighing 3.70 lbs. Cannot add this item The knapsack has 5 items weighing 11.70 lbs. Cannot add this item Cannot add this item Weight capacity of this knapsack: 8.00 lbs. The knapsack has 2 items weighing 4.25 lbs.
Type in the weight capacity of the knapsack: 10 Type in the weight of item 1: 1.5 Type in the weight of item 2: 2.5 Type in the weight of item 3: 3.5 The knapsack has 3 items weighing 7.50 lbs.If, in the above execution, you instead input 6 as capacity, one error message should be printed and the knapsack should result in 2 items weighing 4.00 lbs.