hey como estas gracias por responderme aqui te dejo el programo un poquito mas mejorado aunque todavia me da errors tambien te voy a dejar el archivo espero puedas ayudarme
import java.util.Scanner;
import java.io.*; // needed for file and I/O classes
public class Program6
{
private static Scanner keyboard = new Scanner(System.in);
public static void main(String[] args) throws IOException
{
final int MAX_SIZE = 100;
int numOfArray;
Fan[] fans = new Fan[MAX_SIZE];
numOfArray = fillArray(fans, MAX_SIZE);
listFanData(fans, numOfArray);
/*
bubbleSortByFan();
bubbleSortByAge();
*/
}
public static int fillArray(Fan[] followers, int max) throws IOException
{
String fileName;
//String names = "";
//int ages;
int count = 0;
int i = 1;
int a = 0;
String[] names = new String[max];
int[] ages = new int[max];
System.out.print("Enter the file name: ");
//fileName = keyboard.nextLine();
// open the file
File theFile = new File("FanData.txt");
// make sure the file exists
if (!theFile.exists())
System.out.println("File + fileName + not found");
else
{
//create a scanner object for to read the file
Scanner inputFile = new Scanner(theFile);
// use a while loop that process the document information
while (inputFile.hasNext() && count < followers.length)
{
if (i*2-1 == count)
{
ages[a] = inputFile.nextInt();
inputFile.nextLine();
i++;
a++;
}
else
names[a] = inputFile.nextLine();
count++;
}
// close the file
inputFile.close();
for (int j = 0; j <= (count / 2); j++)
{
followers[j] = new Fan(names[j], ages[j]);
}
System.out.println("There are " + (count / 2) + " fans.");
}
return (count / 2);
}
public static void listFanData(Fan[] follow, int num) throws IOException
{
System.out.println("\nList all Mr. Rogeres' fans");
for (int i = 0; i <= num; i++)
{
//System.out.printf("%0s %11d\n ", follow[i].getName(), follow[i].getAge());
System.out.println(follow[i].getName());
System.out.println(follow[i].getAge());
}
}
}