/* * TestMain.java * * Created on September 30, 2007, 12:33 PM * * @Author Dan Fleck, * George Mason University * Computer Science Department */ /** * * @author dfleck */ public class TestMain { /** This program will test the Question and SmartQuestion class. */ public static void main(String args[]) { Question q = new Question(); // You must surround Question's askQuestion with a try/catch block because // it throws checked Exceptions try { char answer = q.askQuestion("Q1. What is the first letter of the alphabet? [a, b, c]", new char[] { 'a','b','c' }); if ('a' == answer ) { System.out.println("You're right"); } else { System.out.println("You're wrong"); } } catch (NotACharException e) { System.out.println(e.getMessage()); } catch (NotAValidCharException e) { System.out.println(e.getMessage()); } // Notice that SmartQuestion does not need a try/catch block because // no checked Exceptions are thrown from SmartQuestion. SmartQuestion sq = new SmartQuestion(); char answer = sq.askQuestion("SQ1. What is the last letter of the alphabet? [x, y, z]", new char[] { 'x','y','z' }); if ('z' == answer ) { System.out.println("You're right"); } else { System.out.println("You're wrong"); } } }