I want an input file with zero data, 50 names and numbers. I used looping and arrays to hold the names and numbers. I think there's something wrong with my array or loop statements.
import java.util.Scanner;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.PrintWriter;
import java.io.FileOutputStream;
public class StudentParty
{
public static void main(String[] args)
{
String name1;
double number1;
String name2;
double number2;
String name3;
double number3;
double count = 3;
double total = 0;
double average;
String [] name = new String [50];
String [] number = new String [50];
Scanner fileIn = null;
PrintWriter OutputStream = null;
try
{
fileIn = new Scanner
(new FileInputStream
("StudentPartyInput.txt"));
OutputStream = new PrintWriter(new FileOutputStream
("StudentPartyOutput.txt"));
}
catch (FileNotFoundException e)
{
System.out.println("File not foud.");
System.exit(0);
}
while (fileIn.hasNextLine())
{
line = fileIn.nextLine();
count++;
name1 = fileIn.nextLine();
number1 = fileIn.nextDouble();
fileIn.nextLine();
total = total + number1;
}
average = total / count;
fileIn.close();
OutputStream.println();
OutputStream.println(name1 + " had " + (number1 - average) + " more drinks than the average ");
OutputStream.println(name2 + " had " + (number2 - average) + " more drinks than the average ");
OutputStream.println(name3 + " had " + (number3 - average) + " more drinks than the average ");
OutputStream.close();
}
}