//COP3330 Example
//9/8/2006
//Performs summation with various expressions

public class Summation {
	
	//instance variables:
	int start;
	int stop;
	
	
	public Summation (int start, int stop) {
		//initialize the start and stop
		this.start = start;
		this.stop = stop;
	}
	
	public Summation(int stop){
		//constructor with default start of 0
		this.stop = stop;
		this.start = 0;
	}
	
	public Summation(double start, double stop){
		//constructoro for doubles
		//Converts the start by taking the ceiling
		this.start = (int)Math.ceil(start);
		this.stop = (int)stop;
	}
	
	public double expression1() {
		//basic summation i
		int i = this.start;
		double result = 0;
		do {
			result += i;
			i++;
		} while (i <= stop);
		return result;
	}
	
	public double expression2(){
		//basic summation with for loop
		double result = 0;
		for (int i = this.start; i <= this.stop; i++)
			result += i;
		return result;
	}
	
	public static void main (String [] args){
		Summation sum1 = new Summation(0, 5);
		Summation sum2 = new Summation(4);
		Summation sum3 = sum2;//copying location
		
		System.out.println("sum1 e1: " + sum1.expression1());
		System.out.println("sum2 e2: " + sum1.expression2());
		System.out.println("sum3 e1: " + sum2.expression1());//note this using a different start and stop
	}
	
}
