·
void addValue(int x)
·
int getLargest()
·
int getSmallest()
Keep track of the smallest and largest values that you've seen so far. Then use the Math.min and Math.max methods to update them in the addValue method. What should you use as initial values? Hint: Integer.MIN_VALUE, Integer.MAX_VALUE.
Write a test program DataSetTester that calls addValue four times and prints the expected and actual results.
public class DataSet
{
public DataSet()
{
final MIN_VALUE
final MAX_VALUE
largest = Integer.MIN_VALUE;
smallest = Integer.MAX_VALUE;
}
public void addValue(int x)
{
currentMax = Math.max(currentMax = largest);
currentMin = Math.min(currentMin = smallest);
}
public int getLargest()
{
return largest;
}
public int getSmallest()
{
return smallest;
}
private int largest;
private int smallest;
}
C:\Documents and Settings\default\My Documents\Downloads\DataSet.java:5: <identifier> expected
final MIN_VALUE
^
1 error
Tool completed with exit code 1
This post has been edited by William_Wilson: 26 October 2008 - 05:04 PM

New Topic/Question
Reply




MultiQuote









|