氏名と 4 つの販売番号を含むファイルを使用しています。アレイを作成しました。表示するすべての人物と売上高を使用したい。ファイルの形式は次のとおりです。
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.");
}