Advertisement
Five_NT

knapsack

Mar 12th, 2017
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.66 KB | None | 0 0
  1. import java.util.ArrayList;
  2. public class Knapsack implements Item {
  3.  
  4.     private int capacity;
  5.     private static ArrayList<AbstractItem> knapsacks;
  6.  
  7.     /** Constructor pentru knapsack, unde se initializeaza capacitatea rucsacului si se creaza un rucsac */
  8.     public Knapsack(int x) {
  9.         this.capacity = x;
  10.         this.knapsacks = new ArrayList<>(this.capacity);
  11.     }
  12.  
  13.     /** add(Item...) adauga o carte in rucsac */
  14.     public void add(AbstractItem... item) {
  15.         for (AbstractItem i : item) {
  16.             if (knapsacks.size() < this.capacity) {
  17.                 knapsacks.add(i);
  18.                 this.capacity++;
  19.             }
  20.         }
  21.     }
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement