001 package com.croftsoft.apps.quiz; 002 003 import java.io.Serializable; 004 005 import com.croftsoft.core.lang.NullArgumentException; 006 import com.croftsoft.core.text.sml.*; 007 008 /********************************************************************* 009 * A question/answer pair with reference. 010 * 011 * @version 012 * 2001-06-10 013 * @since 014 * 2001-06-10 015 * @author 016 * <a href="https://www.croftsoft.com/">David Wallace Croft</a> 017 *********************************************************************/ 018 019 public final class QuizItem 020 implements Serializable 021 ////////////////////////////////////////////////////////////////////// 022 ////////////////////////////////////////////////////////////////////// 023 { 024 025 private static final long serialVersionUID = 1L; 026 027 private String question; 028 029 private String answer; 030 031 private String reference; 032 033 ////////////////////////////////////////////////////////////////////// 034 ////////////////////////////////////////////////////////////////////// 035 036 public static QuizItem fromSmlNode ( SmlNode smlNode ) 037 ////////////////////////////////////////////////////////////////////// 038 { 039 String question = smlNode.getString ( "question" ); 040 041 String answer = smlNode.getString ( "answer" ); 042 043 String reference = smlNode.getString ( "reference" ); 044 045 return new QuizItem ( question, answer, reference ); 046 } 047 048 ////////////////////////////////////////////////////////////////////// 049 ////////////////////////////////////////////////////////////////////// 050 051 public QuizItem ( 052 String question, 053 String answer, 054 String reference ) 055 ////////////////////////////////////////////////////////////////////// 056 { 057 NullArgumentException.check ( this.question = question ); 058 059 this.answer = answer; 060 061 this.reference = reference; 062 } 063 064 ////////////////////////////////////////////////////////////////////// 065 ////////////////////////////////////////////////////////////////////// 066 067 public String getQuestion ( ) { return question; } 068 069 public String getAnswer ( ) { return answer; } 070 071 public String getReference ( ) { return reference; } 072 073 ////////////////////////////////////////////////////////////////////// 074 ////////////////////////////////////////////////////////////////////// 075 076 public void setQuestion ( String question ) 077 ////////////////////////////////////////////////////////////////////// 078 { 079 this.question = question; 080 } 081 082 public void setAnswer ( String answer ) 083 ////////////////////////////////////////////////////////////////////// 084 { 085 this.answer = answer; 086 } 087 088 public void setReference ( String reference ) 089 ////////////////////////////////////////////////////////////////////// 090 { 091 this.reference = reference; 092 } 093 094 ////////////////////////////////////////////////////////////////////// 095 ////////////////////////////////////////////////////////////////////// 096 097 public SmlNode toSmlNode ( ) 098 ////////////////////////////////////////////////////////////////////// 099 { 100 SmlNode rootSmlNode = new SmlNode ( "QuizItem" ); 101 102 rootSmlNode.add ( new SmlNode ( "question", question ) ); 103 104 if ( answer != null ) 105 { 106 rootSmlNode.add ( new SmlNode ( "answer", answer ) ); 107 } 108 109 if ( reference != null ) 110 { 111 rootSmlNode.add ( new SmlNode ( "reference", reference ) ); 112 } 113 114 return rootSmlNode; 115 } 116 117 public String toString ( ) 118 ////////////////////////////////////////////////////////////////////// 119 { 120 return toSmlNode ( ).toString ( ); 121 } 122 123 ////////////////////////////////////////////////////////////////////// 124 ////////////////////////////////////////////////////////////////////// 125 }