import lejos.nxt.*;

public class FilteredLightSensor {
	public FilteredLightSensor(SensorPort port) {

	}

	public void setFloodlight(boolean state) {
	}

	public int getLightData(){
		return 0;
	}
}

@@ -17,139 +17,716 @@
 .*;%0A
-%0Apublic class FilteredLightSensor %7B%0A%09public FilteredLightSensor(SensorPort port) %7B%0A%0A%09%7D%0A%0A%09public void setFloodlight(boolean state) %7B
+import lejos.robotics.Color;%0A%0A// NOT THREAD SAFE, ONLY USE WITH SINGLE THREAD AND PERIODIC SAMPLING%0Apublic class FilteredLightSensor %7B%0A%09private final ColorSensor handle;%0A%09// Array of last sensor samples%0A%09private int%5B%5D samples;%0A%09// Current count in the array%0A%09private int currentCount;%0A%09// Current index in the array for the next sample%0A%09private int index;%0A%0A%09public FilteredLightSensor(SensorPort port) %7B%0A%09%09handle = new ColorSensor(port);%0A%09%7D%0A%0A%09public void setSampleCount(int sampleCount) %7B%0A%09%09samples = new int%5BsampleCount%5D;%0A%09%09currentCount = 0;%0A%09%09index = 0;%0A%09%7D%0A%0A%09public void setFloodlight(boolean state) %7B%0A%09%09if (state) %7B%0A%09%09%09handle.setFloodlight(Color.GREEN);%0A%09%09%7D else %7B%0A%09%09%09handle.setFloodlight(Color.NONE);%0A%09%09%7D
 %0A%09%7D%0A
@@ -756,20 +756,669 @@
 ta()
+ 
 %7B%0A%09%09
-return 0
+final int sampleCount = samples.length;%0A%09%09// Get the light value%0A%09%09samples%5Bindex%5D = handle.getLightValue();%0A%09%09// Compute the sample count, maxing at the array size%0A%09%09currentCount = Math.min(currentCount + 1, sampleCount);%0A%09%09// Compute the next index, wrapping around%0A%09%09index = (index + 1) %25 sampleCount;%0A%09%09// Get the start of the array, which is different before wrapping%0A%09%09int start = currentCount %3C sampleCount ? 0 : index;%0A%09%09int average = 0;%0A%09%09// Compute the average of the samples%0A%09%09for (int i = 0; i %3C currentCount; i++) %7B%0A%09%09%09// Get the sample with a wrapping index%0A%09%09%09average += samples%5B(start + i) %25 sampleCount%5D;%0A%09%09%7D%0A%09%09return average / currentCount
 ;%0A%09%7D

Implement LightSensor