import java.util.
*; //para magamit ang Scanner
import java.io.*; //para magamit ung Triplets sa File Read
import java.text.*;
public class fileread
{
public static void main(String []args)throws IOException
{
Scanner sc = new Scanner(System.in);
//variables needed for storage of students information
String studno = "", lname = "", fname = "", mi = "";
String data=""; //a variable that will hold the value came from the array
String answer=""; //a variable for asking continuation of the program
String students[]; //an array that will hold the values from the notepad
//variable check is used as a pointer if a record was found or not
int age = 0, check = 0;
double genave = 0;
//fis tells what is the file type where records are stored
FileInputStream fis = new FileInputStream("studentinfo.txt");
//dis converts the content of the file into data
DataInputStream dis = new DataInputStream(fis);
//br reads the data that will be stored in an array
BufferedReader br = new BufferedReader(new InputStreamReader(dis));
while(true)
{
System.out.print("Enter the student no.: ");
studno = sc.next();
//used to read the content of the file and transfer to data
while((data = br.readLine())!=null)
{
//separate the categories of data using a comma symbol ","
students = data.split(", ");
//checks if the input studno matched a record in the database
if(studno.equals(students[0]))
{
/*
fetch and display the record based on the index location
in the array
*/
System.out.println("First Name: " + students[2]);
System.out.println("Middle Initial: " + students[3]);
System.out.println("Last Name: " + students[1]);
System.out.println("Age: " + students[4]);
System.out.println("General Average: " + students[5]);
//change the value of the variable check if a record was found
check = 1;
}
}
//0 - if record not found, 1 - if record was found
if(check == 0)
{
System.out.println("Records Not Found!!!");
}
//return the value to 0 to prepare for another transaction
check = 0;
/*
this will reset the position of the pointer to the beginning
of the data/array to prepare for another transaction
*/
fis.getChannel().position(0);
System.out.print("Do you want to continue? Yes/No: ");
answer = sc.next();
if(answer.equalsIgnoreCase("No"))
{
System.out.print("The Program Will Terminate");
System.exit(0);
}
}
}
}