Class Knapsack

java.lang.Object
  extended by Knapsack

public class Knapsack
extends java.lang.Object

Class for knapsack objects with a weight capacity

Version:
(a version number or a date)
Author:
(your name)

Constructor Summary
Knapsack()
          Constructor for objects of class Knapsack.
Knapsack(double cap)
          Constructor for objects of class Knapsack.
 
Method Summary
 void addItem(double weight)
          Adds an item of the given weight to the knapsack.
 double getCapacity()
          Returns the weight capacity of the knapsack
 int getItemCount()
          Returns the number of items in the knapsack
 double getTotalWeight()
          Returns the total weight of the items in the knapsack
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Knapsack

public Knapsack()
Constructor for objects of class Knapsack. A knapsack has a weight limit of 15 lbs.


Knapsack

public Knapsack(double cap)
Constructor for objects of class Knapsack. Weight limit/capacity is provided as a parameter.

Method Detail

addItem

public void addItem(double weight)
Adds an item of the given weight to the knapsack. If the item is greater than 5 lbs or if it will cause the total weight of the knapsack to be greater than the capacity, then the item is not added and "Cannot add this item" is printed

Parameters:
weight - weight of the item to be added

getCapacity

public double getCapacity()
Returns the weight capacity of the knapsack

Returns:
capacity

getItemCount

public int getItemCount()
Returns the number of items in the knapsack

Returns:
number of items

getTotalWeight

public double getTotalWeight()
Returns the total weight of the items in the knapsack

Returns:
total weight