-
Notifications
You must be signed in to change notification settings - Fork 82
/
IntListVer1.java
41 lines (38 loc) · 1.2 KB
/
IntListVer1.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
/**
* A class to provide a simple list of integers.
* List resizes automatically. Used to illustrate
* various design and implementation details of
* a class in Java.
*
* Version 1 only contains the instance variables and
* the constructors
* @author scottm
*
*/
public class IntListVer1 {
// class constant for default size
private static final int DEFAULT_CAP = 10;
//instance variables
private int[] iValues;
private int iSize;
/**
* Default constructor. Creates an empty list.
*/
public IntListVer1(){
//redirect to single int constructor
this(DEFAULT_CAP);
//other statments could go here.
}
/**
* Constructor to allow user of class to specify
* initial capacity in case they intend to add a lot
* of elements to new list. Creates an empty list.
* @param initialCap > 0
*/
public IntListVer1(int initialCap) {
assert initialCap > 0 : "Violation of precondition. IntListVer1(int initialCap):"
+ "initialCap must be greater than 0. Value of initialCap: " + initialCap;
iValues = new int[initialCap];
iSize = 0;
}
}