我正在使用一个包含名字和姓氏以及四个销售编号的文件。我创建了一个数组。我想使用所有的人员和销售数据来显示。这是文件的格式。
Willow Mary
154 189.5 95 76 63.51
这是我正在尝试的。它一直在我的捕获块。
import java.io.File;
import java.util.Scanner;
public class Assignment10 {
public static final int NUM_SALESPEOPLE = 20;
public static void main(String[] args) {
SalesPerson[] list = new SalesPerson[NUM_SALESPEOPLE];
try {
int people = 0;
Scanner fileInput = new Scanner(new File("A10.txt"));
while (fileInput.hasNext()) {
String firstName = fileInput.nextLine();
String lastName = fileInput.nextLine();
double firstSales = fileInput.nextDouble();
double secondSales = fileInput.nextDouble();
double thirdSales = fileInput.nextDouble();
double fourthSales = fileInput.nextDouble();
SalesPerson person = new SalesPerson(firstName, lastName,
firstSales, secondSales, thirdSales, fourthSales);
list[people] = person;
people++;
}
} catch (Exception ex) {
System.out.println("Error opening file.");
}