这是我第一次发帖。我在大学工作中需要一些帮助,我需要编写代码来搜索输入的学生ID,并显示学生在场,迟到和缺勤的周数以及文件中的总成绩。 (1 =当前,0.5 =延迟,0表示缺席),我要决定是否要分组。 1、0.5和0来计算出学生在校的周数。当我尝试编译时,它说找不到MatchResult所在的符号。将不胜感激:)
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;
public class ClassAttendance{
public static void main(String[] args){
try{
Scanner sc = new Scanner(System.in);
Scanner filescanner = new Scanner(new File("attendance.csv"));
System.out.println("Please enter your student id: ");
String student = sc.next();
int length = String.valueOf(student).length();
if(length != 10){
System.out.println("You enter wrong student id");
System.exit(-1);
}
int lineNum = 0;
while(filescanner.hasNextLine()){
String line = filescanner.nextLine();
lineNum++;
if(line.contains(student)){
Scanner s = new Scanner(line);
s.findInLine("0.5");
MatchResult re = s.match(); //this is where i have trouble
for (int i=1; i<re.groupCount(); i++)
System.out.println(re.group(i));
}
else{
System.out.println("NA");
}
}
}catch (FileNotFoundException e) {
System.out.println("Error: File not found!");
}
}
}