/** A program to test the CourseRecord, StudentFile, and StudentRecord classes. */ import java.util.*; public class A4 { /** Finds the student record, if any, with a given ID number. Traverses it if found, prints an error message otherwise. In either case, skips a line afterwards. */ public static void findAndTraverseStudentRecord( StudentFile sf, int n) { StudentRecord sr = sf.findStudentRecord(n); if (sr == null) System.out.println("no record -- can't traverse"); else sr.traverse(); System.out.println(); } /** A test program for Assignment 4, CS 146, Spring 2003 @param args is ignored */ public static void main(String[] args) { StudentFile sf = new StudentFile(); StudentRecord sr = new StudentRecord("john", "doe", 1776); System.out.println(); System.out.print(" " + sr.add(null)); System.out.print(" " + sr.add(new CourseRecord(1046,1997,-85))); System.out.print(" " + sr.add(new CourseRecord(1042,1997,79))); System.out.print(" " + sr.add(new CourseRecord(2146,1998,81))); System.out.print(" " + sr.add(new CourseRecord(2146,1998,99))); // an update System.out.print(" " + sr.add(new CourseRecord(2151,1999,93))); System.out.print(" " + sr.add(new CourseRecord(1031,1997,105))); System.out.print(" " + sr.add(new CourseRecord(1046,1997,85))); // an update System.out.print(" " + sr.add(new CourseRecord(2151,1999,94))); // an update System.out.println(); System.out.println(); sr.traverse(); System.out.println(); System.out.print(sr.findGrade(1000,1997) + " "); System.out.print(sr.findGrade(1046,1997) + " "); System.out.print(sr.findGrade(1031,1997) + " "); System.out.print(sr.findGrade(1046,1998) + " "); System.out.print(sr.findGrade(2146,1998) + " "); System.out.print(sr.findGrade(2151,1999) + " "); System.out.print(sr.findGrade(2222,1999) + " "); System.out.println(); System.out.println(); sf.add(sr); System.out.println(sf.add(new StudentRecord("jane", "doe", 1984))); System.out.println(sf.add(new StudentRecord("jose", "state", 1857))); System.out.println(sf.add(null)); System.out.println(sf.add(new StudentRecord("pete","lee",2001))); System.out.println(sf.add(new StudentRecord("repeat","lee",2001))); System.out.println(sf.add(new StudentRecord("joyce","daley",1001))); System.out.println(sf.add(new StudentRecord("rejoice","daley",1001))); System.out.println(); findAndTraverseStudentRecord(sf,1492); findAndTraverseStudentRecord(sf,1001); findAndTraverseStudentRecord(sf,1776); findAndTraverseStudentRecord(sf,1857); findAndTraverseStudentRecord(sf,1984); findAndTraverseStudentRecord(sf,2001); List ls = sf.getCourseList(1492); System.out.println(ls); ls = sf.getCourseList(1861); System.out.println(ls); ls = sf.getCourseList(1776); Iterator it = ls.iterator(); it.next(); it.remove(); System.out.println(ls); sr.traverse(); System.out.println(); sf.traverseByNumber(); } }