import java.util.ArrayList;
public class WeatherData
{
private ArrayList temperatures;
public WeatherData( double[] data )
{
temperatures = new ArrayList();
for( int i = 0; i < data.length; i++ )
{
temperatures.add( data[i] );
}
}
/**
* Cleans the data by removing from temperatures all values that are
* less than lower and all values that are greater than upper,
* as described in part (a)
*/
public void cleanData( double lower, double upper )
{
//write the code for Part A
}
/**
* Returns the length of the longest heat wave found in temperatures,
* as described in part (b)
* Precondition: There is **at least one** heat wave in temperatures
* based on threshold.
*/
public int longestHeatWave( double threshold )
{
//write the code for Part B
return 0; // Statement to allow compilation, change if necessary
}
public String toString()
{
return temperatures.toString();
}
}
|
Use this Java program to test your answer to question A:
public class TestPartA
{
public static void main(String[] args)
{
double[] data = {99.1, 142.0, 85.0, 85.1, 84.6, 94.3, 124.9,
98.0, 101.0, 102.5};
WeatherData x = new WeatherData(data);
System.out.println( x );
x.cleanData( 85.0, 120.0 );
System.out.println( x );
}
}
|
The correct answer is:
[99.1, 142.0, 85.0, 85.1, 84.6, 94.3, 124.9, 98.0, 101.0, 102.5] [99.1, 85.0, 85.1, 94.3, 98.0, 101.0, 102.5] |
Use this Java program to test your answer to question B:
import java.util.Arrays;
public class TestPartB
{
public static void main(String[] args)
{
double[] data = {100.5, 98.5, 102.0, 103.9, 87.5, 105.2, 90.3,
94.8, 109.1, 102.1, 107.4, 93.2};
System.out.println( Arrays.toString(data) );
WeatherData x = new WeatherData(data);
System.out.println( x.longestHeatWave(100.5) );
System.out.println( x.longestHeatWave(95.2) );
}
}
|
The correct answer is:
[100.5, 98.5, 102.0, 103.9, 87.5, 105.2, 90.3, 94.8, 109.1, 102.1, 107.4, 93.2] 3 4 |