Guest User

Untitled

a guest
May 22nd, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.90 KB | None | 0 0
  1. public class TaskList {
  2.  
  3.     /**
  4.      * Capacity of task's array.
  5.      */
  6.     private static final int CAPACITY = 10;
  7.     /**
  8.      * Index of last element in array
  9.      */
  10.     private int current;
  11.     /**
  12.      * Array of tasks
  13.      */
  14.     private Task[] element;
  15.  
  16.     /**
  17.      * Empty constuctor
  18.      */
  19.     public TaskList() {
  20.         element = new Task[CAPACITY];
  21.         current = 0;
  22.     }
  23.  
  24.     /**
  25.      * Add task to array. If array is full makes new array and add task to
  26.      * new array.
  27.      * @param task added task
  28.      */
  29.     public void add(Task task) {
  30.         if (current >= element.length) {
  31.             Task[] temp = new Task[this.size() + CAPACITY];
  32.             int index = 0;
  33.             for (Task elem : element) {
  34.                 temp[index++] = elem;
  35.             }
  36.             element = temp;
  37.         }
  38.         element[current] = task;
  39.         current++;
  40.     }
Add Comment
Please, Sign In to add comment