/** KnapsackItem.java * J Scott Cameon *This class holds info on a specific item *that can go into a Knapsack */ import java.io.*; public class KnapsackItem { private int weight; /*weight of item*/ private int value; /*value of item*/ public KnapsackItem() {} /*Copy constructor*/ public KnapsackItem(KnapsackItem ki) { weight = ki.weight; value = ki.value; } /*parameterized constructor*/ public KnapsackItem(int weight, int value) { this.weight = weight; this.value = value; } /* returns the Weight of the object*/ public int getWeight() { return weight; } /* returns the Value of the object*/ public int getValue() { return value; } /* returns a String description of Item*/ public String toString() { StringWriter sw = new StringWriter(); sw.write("Weight: "); sw.write((new Integer(weight)).toString()); sw.write(" Value: "); sw.write((new Integer(value)).toString()); return sw.toString(); } }