import java.io.*;
import java.util.*;
public class NumberAnalysis
{
public static void main(String[] args)throws Exception
{
Scanner s = new Scanner(new File("Numbers.txt"));
System.out.println("Here are the numbers that are in the file:");
while (s.hasNext())
System.out.println(s.next());
NumberTotal nt = new NumberTotal("Numbers.txt");
System.out.println("The total of the numbers in the array are: " + nt.getTotal());
Average ave = new Average("Numbers.txt");
System.out.println("The average of the numbers in the array are: " + ave.getAverage());
System.out.println("The lowest number is: ");
System.out.println("The highest number is: ");
}
}
gets the average
import java.util.Scanner;
import java.io.*;
public class Average
{
private float average;
public Average(String filename) throws IOException
{
String str;
File file = new File(filename);
Scanner inputFile = new Scanner(file);
float total = 0;
while (inputFile.hasNext())
{
float number = inputFile.nextFloat();
total = total + number;
average = total /19;
}
inputFile.close();
}
public float getAverage()
{
return average;
}
}
gets the total
import java.util.Scanner;
import java.io.*;
public class NumberTotal
{
private double sum;
public NumberTotal(String filename) throws IOException
{
String str;
File file = new File(filename);
Scanner inputFile = new Scanner(file);
sum = 0.0;
while (inputFile.hasNext())
{
double number = inputFile.nextDouble();
sum = sum + number;
}
inputFile.close();
}
public double getTotal()
{
return sum;
}
}
any help knowledge would be helpful. Thanks

Ask A New Question
Reply





MultiQuote





|