import java.util.*;
import java.lang.*;
import java.io.*;
public class MinorAssignment_PartB {
public static void main(String[] args) throws Exception {
List<StudentMarks> marks = new ArrayList<StudentMarks>();
String File = "studentinfo.txt";
Scanner scan = new Scanner(new File(File));
scan.useDelimiter("[,|\\n]");
while(scan.hasNext()){
//the error refers to this part here
marks.add(new StudentMarks(scan.next(), scan.next(), scan.nextDouble(), scan.nextDouble(), scan.nextDouble(), scan.nextDouble()));
System.out.printf("%-15s %-15s %-15s %-15s %-15s %-15s %-15s %-15s %n", "Student Name", "Student Fan", "Part A", "Part B", "Part C", "Part D", "Mark", "Grade");
for (int i = 0; i < marks.size()-1; i++) {
System.out.println(marks.get(i));
}
}
}
}
我不知道如何解决它,它是在循环和读取文本文件时,其中包含 2 个字符串,然后是 4 个用逗号分隔的双精度,并且有 10 行要循环。
任何帮助将非常感激。
这是 studentinfo.txt 中的内容,但每个新人都在一行
Adam Adamson,adam0001,85.4,79.8,82.4,86.1 Bethany Bright,brig0001,89.7,85.6,84.2,82.9 Cameron Carlson,carl0001,55.45,49.82,60.4,42.27 David Dawson,daws0001,72.6,78.49,80.2,65. ,elli0001,50.2,35.88,48.41,58.37 Frances Fitz,fitz0001,78.9,75.67,82.48,79.1 Greg Gregson,greg0001,24.3,32.88,29.72,28.4 Harriett Hope,hope0001,52.2,58.93,61.5,603. ,88.4,91.23,90.05,92.46 杰西卡·琼斯,jone0001,82.33,89.74,81.3,84.85