📄 querystudent.java
字号:
import java.util.*;
import java.io.*;
import java.lang.*;
public class QueryStudent
{
public static void main(String args[])
{
try{
System.out.println("Please input student name to query or input 'stop' to end query");
BufferedReader readfile = new BufferedReader(new FileReader("database.csv"));
BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
String inputName = (input.readLine()).trim();
String line;
int total;
int average;
while(!(inputName.equals("stop")))
{
Student student1 = new Student(inputName);
while((line = readfile.readLine())!=null)
{
String [] record = line.trim().split(",");
Integer i;
i = new Integer(record[2]) ;
CompareString s=new CompareString();
boolean flag=s.compare(inputName,record[0]);
if(flag==true)
{
Mark newmark;
newmark = new Mark(record[1],i);
student1.addMark(newmark);
}
}
if(student1.getSize()==0)
System.out.println("There is no record for this student!!!");
else
{
student1.showMarks();
total = student1.getTotalScore();
average = total / student1.getSize();
System.out.print("The total score is: ");
System.out.println(total);
System.out.print("The average score is: ");
System.out.println(average);
}
input = new BufferedReader(new InputStreamReader(System.in));
inputName = (input.readLine()).trim();
}
readfile.close();
}
catch(FileNotFoundException e)
{
System.out.println("File not found");
}
catch(IOException e)
{
System.out.println("IO Exception");
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -