Advertisement
Guest User

Untitled

a guest
Jan 17th, 2019
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.64 KB | None | 0 0
  1. public class ArrayBag<T> implements BagInterface<T>{
  2.  
  3.     private final T[] bag;
  4.     private int numberOfItems;
  5.  
  6.     private static final int MAX_CAPACITY = 100;
  7.     private static final int DEFAULT_CAPACITY = 20;
  8.  
  9.     public ArrayBag(){
  10.         this(DEFAULT_CAPACITY);
  11.     }
  12.  
  13.     Public ArrayBag(int capacity){
  14.         if(capacity>MAX_CAPACITY){
  15.             throw new IllegalStateException(“An ArrayBag is created with a capacity that exceeds the maximum capacity”);
  16.         }
  17.         @SuppressWarnings(“unchecked”)
  18.         T[] temp = new Object[capacity];
  19.         bag = temp;
  20.         numberOfItems = 0;
  21.     }
  22.  
  23.     @Override
  24.     public boolean isEmpty() {
  25.         return false;
  26.     }
  27.  
  28.     //Other methods below
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement