// Classes to do Text-based file Input/Output and simple parsing import java.io.*; class Student { String name, ssn; int age; Student (String n, String s, int a) { name = new String(n); ssn = new String(s); age = a; } void display () { System.out.println("SSN: " + ssn + "; Name: " + name + " ; Age: " + age); } } class StudentDB { Student db[]; int num_students = 0; int maxsize; StudentDB (int size) { maxsize = size; db = new Student[size]; } void add_student (Student x) { if (num_students == maxsize) { System.out.println("Database Full"); return; } db[num_students] = x; num_students++; } void show_all () { System.out.println("Report of students in list: "); for (int i=0; i < num_students; i++) db[i].display(); } void store_data (String output_file) throws IOException { // 2nd parameter to the constructor PrintWriter dout = new PrintWriter(new BufferedWriter (new FileWriter(output_file)), true); for (int i=0; i < num_students; i++) dout.println(db[i].ssn + " " + db[i].name + " " + db[i].age); } } class simple { public static void main (String args[]) throws IOException { StudentDB database = new StudentDB(25); String name, ssn, line, remaining; int age, pos, ssn_start, age_start; String input_file, output_file; BufferedReader din = new BufferedReader(new InputStreamReader(System.in)); System.out.print("Enter input file name: "); input_file = din.readLine(); System.out.print("Enter output file name: "); output_file = din.readLine(); din = new BufferedReader(new FileReader(input_file)); // read the data and create the data structures while (true) { line = din.readLine(); if (line == null) break; // parse the input line remaining = line.trim(); pos = remaining.indexOf(" "); name = remaining.substring(0, pos); remaining = remaining.substring(pos+1).trim(); pos = remaining.indexOf(" "); ssn = remaining.substring(0, pos); remaining = remaining.substring(pos+1).trim(); age = Integer.parseInt(remaining); Student foo = new Student(ssn, name, age); database.add_student(foo); } database.show_all(); database.store_data(output_file); } }