querystudent.java
来自「简易的学生课程成绩系统」· Java 代码 · 共 59 行
JAVA
59 行
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 + =
减小字号Ctrl + -
显示快捷键?