// Illustrating inheritance and simple terminal I/O in Java import java.io.*; class StudentDB { public static void main (String args[]) throws IOException { Database D1 = new Database(100); String m, inputstring; String sn; int y; String com; BufferedReader din = new BufferedReader(new InputStreamReader(System.in)); System.out.print("Enter command: "); com = din.readLine(); while (! com.equalsIgnoreCase("QUIT")) { if (com.equalsIgnoreCase("ADD")) { String student_type = null; boolean legal_type = false; while (! legal_type) { System.out.print("Enter student type: (Grad or Student): "); student_type = din.readLine(); if (student_type.equalsIgnoreCase("graduate") || student_type.equalsIgnoreCase("student")) legal_type = true; else System.out.println("Illegal type of Student"); } System.out.print("Enter ssn: "); sn = din.readLine(); System.out.print("Enter name: "); m = din.readLine(); System.out.print("Enter age: "); inputstring = din.readLine(); y = Integer.parseInt(inputstring); if (student_type.equalsIgnoreCase("graduate")) { System.out.print("Enter thesis: "); String thes = din.readLine(); System.out.print("Enter advisor: "); String adv = din.readLine(); D1.add_Student(new Graduate(sn, thes, m, y, adv)); } else D1.add_Student(new Student(sn, m, y)); } else if (com.equalsIgnoreCase( "REMOVE")) { System.out.print("Enter ssn: "); sn = din.readLine(); D1.remove_Student(sn); } else if (com.equalsIgnoreCase("DISPLAY")) { System.out.print("Enter ssn: "); sn = din.readLine(); D1.display_Student(sn); } else if (com.equalsIgnoreCase("SHOWALL")) { D1.display_all(); } else System.out.println("Error case"); System.out.print("Enter next command: "); com = din.readLine(); } } }