thank you.
public class astronomyNumbers1
{
private double[] numbers;
public astronomyNumbers1(String filename) throws IOException
{
final int SIZE = 12;
double[] numbers = new int[SIZE];
int index = 0;
// Create the necessary objects for file input.
File file = new File(filename);
Scanner inputFile = new Scanner(file);
//read the file contents in to the array
while (inputfile.hasNext() && index < numbers.length)
{
numbers[index] = inputfile.nextInt();
index++;
}
public double getTotal()
{
double total = 0.0; // Accumulator
// Add up all the values in the array.
for (double value : numbers)
total += value;
// Return the total.
return total;
}
/**
* The getAverage method returns the average of the
* elements in the array.
*/
public double getAverage()
{
return getTotal() / numbers.length;
}
/**
* The getHighest method returns the highest value
* stored in the array.
*/
public double getHighest()
{
// Store the first value in the array in
// the variable highest.
double highest = numbers[0];
// Search the array for the highest value.
for (int index = 1; index < numbers.length; index++)
{
if (numbers[index] > highest)
highest = numbers[index];
}
// Return the highest value.
return highest;
}
/**
* The getLowest method returns the lowest value
* stored in the array.
*/
public double getLowest()
{
// Store the first value in the sales array in
// the variable lowest.
double lowest = numbers[0];
// Search the array for the lowest value.
for (int index = 1; index < numbers.length; index++)
{
if (sales[index] < lowest)
lowest = numbers[index];
}
// Return the lowest value.
return lowest;
}
inputFile.close();
}
}

New Topic/Question
Reply




MultiQuote








|