/**
 * Thread class for summing numbers within an array.
 *   @author Dave Reed
 *   @version 4/12/17
 */
public class SumThread extends Thread {
	private int[] nums;
	private int minIndex;
	private int maxIndex;
	private int computedSum;
	
	/**
	 * Constructs a SumThread for summing a range of numbers.
	 * @param nums the array of numbers
	 * @param minIndex the minimum index (inclusive) of the range
	 * @param maxIndex the maximum index (exclusive) of the range
	 */
	public SumThread(int[] nums, int minIndex, int maxIndex) {
        this.nums = nums;
        this.minIndex = minIndex;
        this.maxIndex = maxIndex;
        this.computedSum = 0;
	}
	
	/**
	 * Accesses the computer sum of numbers.
	 * @return the sum of the numbers in the specified range
	 */
	public int getSum() {
		return this.computedSum;
	}
	
	/**
	 * Overrides the default run method from Thread.
	 * In this case, sums the numbers in the range and stores in field. 
	 */
	public void run() {
		this.computedSum = 0;
		for (int i = this.minIndex; i < this.maxIndex; i++) {
			this.computedSum += this.nums[i];
		}
	}
}
