// File: Stud_tst.java // Test student class import java.io.*; public class StudentTest { static DataInputStream DataInput=new DataInputStream(System.in); static char GetChoice(String OK) throws java.io.IOException {char Reply; do { Reply=Character.toUpperCase((char)System.in.read()); // System.out.println("*** GOT "+Reply); } while (OK.indexOf(Reply,0)==-1); System.in.read(); // System.out.println("*** HAVE "+Reply); return(Reply); } static int ReadInt() throws java.io.IOException {int Total=0,Sign=1; int Digit; // Eat Blanks while ((Digit=System.in.read())<=32); // Check for - sign if (Digit=='-') Sign=-1; else if (Digit>='0' && Digit<='9') Total=Digit-48; else return(-1); Digit=System.in.read(); while (Digit>='0' && Digit<='9') { Total=(Total*10)+Digit-48; Digit=System.in.read(); } return(Total*Sign); } static char StudentMenu() throws java.io.IOException {System.out.println( "\nSelect:"); System.out.println( "\tA)dd Class"); System.out.println( "\tC)hange Grade"); System.out.println( "\tR)emove Class"); System.out.println( "\tP)rint Student"); System.out.println( "\tH)ours Completed"); System.out.println( "\tS)tudent Name"); System.out.println( "\tE)xit"); return (GetChoice("ACRPHSE")); } static void SetStudentName(Student S) throws java.io.IOException {String Name; System.out.print( "Enter Student Name >"); System.out.flush(); Name=DataInput.readLine(); S.SetName(Name); } static void AddClass(Student S) throws java.io.IOException {int Hours; char Grade; System.out.print( "#Hours? >"); System.out.flush(); Hours=ReadInt(); System.out.print( "Grade? (A-D,F) >"); System.out.flush(); Grade=GetChoice("ABCDF");; S.AddClass(Hours,Grade); } static void ChangeClass(Student S) throws java.io.IOException {int Hours; char OldGrade,NewGrade; System.out.print( "#Hours? >"); System.out.flush(); Hours=ReadInt(); System.out.print( "Old Grade? (A-D,F) >"); System.out.flush(); OldGrade=GetChoice("ABCDF"); System.out.print( "New Grade? (A-D,F) >"); System.out.flush(); NewGrade=GetChoice("ABCDF");; S.ChangeGrade(Hours,OldGrade,NewGrade); } static void RemoveClass(Student S) throws java.io.IOException {int Hours; char Grade; System.out.print( "#Hours? >"); System.out.flush(); Hours=ReadInt(); System.out.print( "Grade? (A-D,F) >"); System.out.flush(); Grade=GetChoice("ABCDF");; S.RemoveClass(Hours,Grade); } public static void main(String[] args) throws java.io.IOException {char Choice; Student StudentA; System.out.println("Choose Initial Student Info:"); System.out.println(" N)ame (BoB Jones) Only A)ll Info E)mpty Object"); switch (Choice=GetChoice("NAE")) { case 'N':StudentA=new Student("Bob Jones");break; case 'A': System.out.print("Hours? >"); System.out.flush(); int Hours=ReadInt(); System.out.print("Points? >"); System.out.flush(); int Points=ReadInt(); StudentA=new Student("Bob Jones",Hours,Points);break; default:StudentA=new Student(); } do { switch (Choice=StudentMenu()) { case 'A':AddClass(StudentA);break; case 'C':if (StudentA.HoursCompleted()!=0) ChangeClass(StudentA);break; case 'R':if (StudentA.HoursCompleted()!=0) RemoveClass(StudentA);break; case 'P':StudentA.PrintStudentInfo();break; case 'H':System.out.println( "Hours Completed:" + StudentA.HoursCompleted()+"\n"); break; case 'S':SetStudentName(StudentA);break; } } while (Choice!='E'); } }