package exercise.writer; /** * This class is used to Parse a Number Question file into it's component * parts that can be used to construct a Number Question Module. * @author Grant K. Olds * @version * @since JDK1.2 */ import java.lang.*; import java.util.*; public class NumberEntryParser extends QuestionEntryParser { private StringBuffer answer; private StringBuffer lessThanXvalue; private StringBuffer lessThanXFeedback; private StringBuffer greaterThanXvalue; private StringBuffer greaterThanXFeedback; private StringBuffer greaterThanEqualToValue; private StringBuffer lessThanEqualToValue; private StringBuffer intervalFeedback; private StringBuffer elseFeedback; private StringBuffer genStrategy; private StringBuffer specificStrategy; private StringBuffer giveAnswer; NumberEntryParser(){} NumberEntryParser( String fileContents) { //contents = fileContents; file = new StringTokenizer( fileContents ); } /** * Gets the answer number * @return the answer as a string null string otherwise. */ public String getAnswer() { return answer.toString(); } /** * Gets the lessThanX number * @return the lessThanX as a string null string otherwise. */ public String getLessThanX() { return lessThanXvalue.toString(); } /** * Gets the lessThanXFeedback * @return the lessThanXFeedback as a string null string otherwise. */ public String getLessThanXFeedback() { return lessThanXFeedback.toString(); } /** * Gets the greaterThanX * @return the greaterThanX as a string null string otherwise. */ public String getGreaterThanX() { return greaterThanXvalue.toString(); } /** * Gets the greaterThanXFeedback * @return the greaterThanXFeedback as a string null string otherwise. */ public String getGreaterThanXFeedback() { return greaterThanXFeedback.toString(); } /** * Gets the greaterThanEqualToX * @return the greaterThanEqualToX as a string null string otherwise. */ public String getGreaterThanEqualToX() { return greaterThanEqualToValue.toString(); } /** * Gets the lessThanEqualToX * @return the lessThanEqualToX as a string null string otherwise. */ public String getLessThanEqualToX() { return lessThanEqualToValue.toString(); } /** * Gets the interval * @return the interval Feedback as a string null string otherwise. */ public String getIntervalFeedback() { return intervalFeedback.toString(); } /** * Gets the elseFeedback * @return the else feedback as a string null string otherwise. */ public String getElseFeedback() { return elseFeedback.toString(); } public String getGenStrategy () { return genStrategy.toString(); } public String getSpecificStrategy () { return specificStrategy.toString(); } public String getGiveAnswer () { return giveAnswer.toString(); } public void parseFile(){} public void parseFile ( String fileContents ) { file = new StringTokenizer ( fileContents ); while ( file.hasMoreTokens() ) { String currToken = file.nextToken(); //if the token is equal to "Section" if ( currToken.equals( "Section:" ) ) { //assign all the tokens to the section string until you reach //Exercise. currToken = file.nextToken(); section = new StringBuffer(); while ( currToken.compareTo( "Exercise:") != 0 ) { section.append ( currToken ).append (" "); currToken = file.nextToken(); } } // assign all tokens to the exercise strint until you reach // "Question:" if ( currToken.equals( "Exercise:" ) ) { exercise = new StringBuffer (); currToken = file.nextToken(); while ( currToken.compareTo( "Question:") != 0 ) { exercise.append ( currToken ); currToken = file.nextToken(); } } // Assign all tokens to the question string until you reach // "Answer:" if ( currToken.equals( "Question:" ) ) { question = new StringBuffer (); currToken = file.nextToken(); while ( currToken.compareTo( "Answer:" ) != 0 ) { question.append ( currToken ).append(" "); currToken = file.nextToken(); } } // Assign all tokens to the answer string until you reach // "Feedback:" if ( currToken.equals( "Answer:" ) ) { answer = new StringBuffer(); currToken = file.nextToken(); while ( currToken.compareTo( "lessThanXvalue:" ) != 0 ) { answer.append ( currToken ).append(" "); currToken = file.nextToken(); } } if ( currToken.equals( "lessThanXvalue:" ) ) { lessThanXvalue = new StringBuffer(); currToken = file.nextToken(); while ( currToken.compareTo( "lessThanXFeedback:" ) != 0 ) { lessThanXvalue.append ( currToken ).append(" "); currToken = file.nextToken(); } } if ( currToken.equals( "lessThanXFeedback:" ) ) { lessThanXFeedback = new StringBuffer(); currToken = file.nextToken(); while ( currToken.compareTo( "greaterThanXvalue:" ) != 0 ) { lessThanXFeedback.append ( currToken ).append(" "); currToken = file.nextToken(); } } if ( currToken.equals( "greaterThanXvalue:" ) ) { greaterThanXvalue = new StringBuffer(); currToken = file.nextToken(); while ( currToken.compareTo( "greaterThanXFeedback:" ) != 0 ) { greaterThanXvalue.append ( currToken ).append(" "); currToken = file.nextToken(); } } if ( currToken.equals( "greaterThanXFeedback:" ) ) { greaterThanXFeedback = new StringBuffer(); currToken = file.nextToken(); while ( currToken.compareTo( "lessThanEqualToValue:" ) != 0 ) { greaterThanXFeedback.append ( currToken ).append(" "); currToken = file.nextToken(); } } if ( currToken.equals( "lessThanEqualToValue:" ) ) { lessThanEqualToValue = new StringBuffer(); currToken = file.nextToken(); while ( currToken.compareTo( "greaterThanEqualToValue:" ) != 0 ) { lessThanEqualToValue.append ( currToken ).append(" "); currToken = file.nextToken(); } } if ( currToken.equals( "greaterThanEqualToValue:" ) ) { greaterThanEqualToValue = new StringBuffer(); currToken = file.nextToken(); while ( currToken.compareTo( "intervalFeedback:" ) != 0 ) { greaterThanEqualToValue.append ( currToken ).append(" "); currToken = file.nextToken(); } if ( currToken.equals( "intervalFeedback:" ) ) { intervalFeedback = new StringBuffer(); currToken = file.nextToken(); while ( currToken.compareTo( "elseFeedback:" ) != 0 ) { intervalFeedback.append ( currToken ).append(" "); currToken = file.nextToken(); } } // Assign all tokens tothe elseFeedback string until you reach // "Hint:" if ( currToken.equals( "elseFeedback:" ) ) { elseFeedback = new StringBuffer(); currToken = file.nextToken(); while ( currToken.compareTo( "genStrategy:" ) != 0 ) { elseFeedback.append ( currToken ).append(" "); currToken = file.nextToken(); } } if ( currToken.equals( "genStrategy:" ) ) { genStrategy = new StringBuffer(); currToken = file.nextToken(); while ( currToken.compareTo( "specificStrategy:" ) != 0 ) { genStrategy.append ( currToken ).append(" "); currToken = file.nextToken(); } } if ( currToken.equals( "specificStrategy:" ) ) { specificStrategy = new StringBuffer(); currToken = file.nextToken(); while ( currToken.compareTo( "giveAnswer:" ) != 0 ) { specificStrategy.append ( currToken ).append(" "); currToken = file.nextToken(); } } if ( currToken.equals( "giveAnswer:" ) ) { giveAnswer = new StringBuffer(); currToken = file.nextToken(); while ( file.hasMoreTokens() ) { giveAnswer.append ( currToken ).append(" "); currToken = file.nextToken(); } giveAnswer.append( currToken ); } } } } public void test() { System.out.println( "The Section is " + section ); System.out.println( "The Exercise is " + exercise ); System.out.println( "The Question is " + question ); System.out.println( "The lessThanXvalue is " + lessThanXvalue ); System.out.println( "The lessThanXFeedback is " + lessThanXFeedback ); System.out.println( "The greaterThanXvalue is " + greaterThanXvalue ); System.out.println( "The greaterThanXFeedback is " + greaterThanXFeedback ); System.out.println( "The lessThanEqualToValue is " + lessThanEqualToValue ); System.out.println( "The greaterThanEqualToValue is " + greaterThanEqualToValue ); System.out.println( "The intervalFeedback is " + intervalFeedback ); System.out.println( "The else Feedback is " + elseFeedback ); System.out.println( "The genStrategy is " + genStrategy ); System.out.println( "The specificStrategy is " + specificStrategy ); System.out.println( "The giveAnswer is " + giveAnswer ); } }