I am designing a generic survey/test taking system. I want the aplication to be designed this way so that the adminitrator can group several questions into one survey question file stored on the hard drive, which can latter be retrieved by other user who wants to do the survey.My question is: is it possible to write several questions into one file?I make a question class, which is abstract. Multiple choice is a subclass of question. True/false is subclass of multiple choice. Later, I may expand all the classes.I checked java doc, and it seems related with object input output stream, or serialization?I am a new bee. Any suggestion is welcome.
|
|
0
|
|
|
|
Reply
|
John
|
4/14/2007 1:53:53 AM |
|
John wrote:> I am designing a generic survey/test taking system. I want the aplication to > be designed this way so that the adminitrator can group several questions > into one survey question file stored on the hard drive, which can latter be > retrieved by other user who wants to do the survey.> > My question is: is it possible to write several questions into one file?Yes.> I make a question class, which is abstract. Multiple choice is a subclass of > question. True/false is subclass of multiple choice. Later, I may expand all > the classes.> I checked java doc, and it seems related with object input output stream, or > serialization?You might use Java serialization, but there are many other ways to do it. For example, JAXB will let you translate objects to an XML text representation and back. This is also a form of serialization, but not Java serialization.-- Lew
|
|
0
|
|
|
|
Reply
|
Lew
|
4/14/2007 2:06:32 AM
|
|
Are there delimiters in the stored file?How does Java know from where to where an objec is in the file?When JAXB will let you translate objects to an XML text representation, what part of the object is translated?For an object of True/Flase question class, is just the question translated? what does the JAXB do with the method?"Lew" <lew@nospam.lewscanon.com> wrote in message news:g4SdneqAt7q1qr3bnZ2dnUVZ_gOdnZ2d@comcast.com...> John wrote:>> I am designing a generic survey/test taking system. I want the aplication >> to be designed this way so that the adminitrator can group several >> questions into one survey question file stored on the hard drive, which >> can latter be retrieved by other user who wants to do the survey.>>>> My question is: is it possible to write several questions into one file?>> Yes.>>> I make a question class, which is abstract. Multiple choice is a subclass >> of question. True/false is subclass of multiple choice. Later, I may >> expand all the classes.>> I checked java doc, and it seems related with object input output stream, >> or serialization?>> You might use Java serialization, but there are many other ways to do it. > For example, JAXB will let you translate objects to an XML text > representation and back. This is also a form of serialization, but not > Java serialization.>> -- > Lew>
|
|
0
|
|
|
|
Reply
|
John
|
4/14/2007 2:35:17 AM
|
|
Please do not top-post.John wrote:> Are there delimiters in the stored file?If you mean XML, yes. They are called "tags".> How does Java know from where to where an objec is in the file?I suggest that you read the documentation for JAXB and for Java serialization.I do not know the details of how Java serialization works in "the stored file", because I've never needed to know.If you are looking to implement a file storage based on storing entire objects it might get very complicated. You could just store the questions and the answers as text, since they are strings to begin with. So instead of serialization, which is difficult, you have reading and writing Strings, which is easy.> When JAXB will let you translate objects to an XML text representation, what > part of the object is translated?As much as you want, but it takes some thought to plan it properly. You may need to learn XML Schema to use it right.> For an object of True/Flase question class, is just the question translated? > what does the JAXB do with the method?It does only what you tell it to do.It's a sort of complicated way to do what a PrintWriter println() and BufferedReader readLine() will probably be able to do for you just fine.You also might consider doing clever things with properties files. They are set up as key=value pairs. You could interpret that as question=answer and take advantage of what Java can do with Properties objects.The Javadocs will help you with such standard things as I/O and Properties.-- Lew
|
|
0
|
|
|
|
Reply
|
Lew
|
4/14/2007 3:58:17 AM
|
|
I don't think that to seperate the text for the question from other parts of a question object is an easy job.I am not sure whether I am correct.But I think that serilization can help me group all the question objects in a survey into an array or arraylist, which can then be written into a file.Then when the user wants to take the survey, the file can be conversely read into an array in memory with its elements being references to the question objects.Each element can then be displayed on the screen to expect the user to input his answer. Of course, different kinds of questions expects different answer, which can be realized through polymorphism.But if I only store the question text part of the question object, I might lose the strucre of the question object. And when the text is read back to memory, how can it be restored to what its coresponding object used to be?John"Lew" <lew@nospam.lewscanon.com> wrote in message news:RNmdnZrwjoLHzL3bnZ2dnUVZ_ualnZ2d@comcast.com...> Please do not top-post.>> John wrote:>> Are there delimiters in the stored file?>> If you mean XML, yes. They are called "tags".>>> How does Java know from where to where an objec is in the file?>> I suggest that you read the documentation for JAXB and for Java > serialization.>> I do not know the details of how Java serialization works in "the stored > file", because I've never needed to know.>> If you are looking to implement a file storage based on storing entire > objects it might get very complicated. You could just store the questions > and the answers as text, since they are strings to begin with. So instead > of serialization, which is difficult, you have reading and writing > Strings, which is easy.>>> When JAXB will let you translate objects to an XML text representation, >> what part of the object is translated?>> As much as you want, but it takes some thought to plan it properly. You > may need to learn XML Schema to use it right.>>> For an object of True/Flase question class, is just the question >> translated? what does the JAXB do with the method?>> It does only what you tell it to do.>> It's a sort of complicated way to do what a PrintWriter println() and > BufferedReader readLine() will probably be able to do for you just fine.>> You also might consider doing clever things with properties files. They > are set up as key=value pairs. You could interpret that as > question=answer and take advantage of what Java can do with Properties > objects.>> The Javadocs will help you with such standard things as I/O and > Properties.>> -- > Lew
|
|
0
|
|
|
|
Reply
|
John
|
4/14/2007 12:32:08 PM
|
|
John wrote:
>I don't think ...
The same thing occurs to me, whenever I see a
top-posted reply to the only responder, who requested..
(Lew)
>> Please do not top-post.
For more infomration on top-posting, see..
<http://www.physci.org/codes/javafaq.html#toppost>
--
Andrew Thompson
http://www.athompson.info/andrew/
Message posted via JavaKB.com
http://www.javakb.com/Uwe/Forums.aspx/java-general/200704/1
|
|
0
|
|
|
|
Reply
|
Andrew
|
4/14/2007 1:24:53 PM
|
|
Please don't top-post.John wrote:> I don't think that to seperate [sic] the text for the question from other parts of > a question object is an easy job.It can be.It all depends on how you wrote the object. Personally, for a question the object type I use is String. Same for the answer. Based on the answers, I would construct on object that represented an entity in my object model, not the question and answer unless that were what my program managed (CBT, surveys).In that case "to separate the text for the question from other parts of a question object is an easy job", as easy aspublic String getQuestion();I would in my own code do as I suggested to you in my last post.-- Lew
|
|
0
|
|
|
|
Reply
|
Lew
|
4/14/2007 2:49:07 PM
|
|
"Lew" <lew@nospam.lewscanon.com> wrote in message news:t9mdnatMaZ55dL3bnZ2dnUVZ_h-vnZ2d@comcast.com...> Please don't top-post.>> John wrote:>> I don't think that to seperate [sic] the text for the question from other >> parts of a question object is an easy job.>> It can be.>> It all depends on how you wrote the object. Personally, for a question > the object type I use is String. Same for the answer. Based on the > answers, I would construct on object that represented an entity in my > object model, not the question and answer unless that were what my program > managed (CBT, surveys).>> In that case "to separate the text for the question from other parts of a > question object is an easy job", as easy as>> public String getQuestion();>> I would in my own code do as I suggested to you in my last post.Could you please offer me some sample code? Here or my mailbox.I would like to see how you construct a question class/object with both question and answer embedded.Thanks!John>> -- > Lew
|
|
0
|
|
|
|
Reply
|
John
|
4/14/2007 3:41:23 PM
|
|
"Lew" <lew@nospam.lewscanon.com> wrote in message news:t9mdnatMaZ55dL3bnZ2dnUVZ_h-vnZ2d@comcast.com...> Please don't top-post.>> John wrote:>> I don't think that to seperate [sic] the text for the question from other >> parts of a question object is an easy job.>> It can be.>> It all depends on how you wrote the object. Personally, for a question > the object type I use is String. Same for the answer. Based on the > answers, I would construct on object that represented an entity in my > object model, not the question and answer unless that were what my program > managed (CBT, surveys).If for a question the object type you use is String, how can you organize the hierarchy of the all those types questions?My design is that there should be a abstract question class, with subclass such as mutiple choice, matching, short answers, true/false etc.True/false can be the subclass of multiple choice.>> In that case "to separate the text for the question from other parts of a > question object is an easy job", as easy as>> public String getQuestion();>> I would in my own code do as I suggested to you in my last post.>> -- > Lew
|
|
0
|
|
|
|
Reply
|
John
|
4/14/2007 4:19:39 PM
|
|
John wrote:..>Could you please offer me some sample code? Here, have some sample code..<sscce>import java.beans.XMLEncoder;import java.beans.XMLDecoder;import java.io.*;public class AnsweredQuestion { public String question; public String answer; public AnsweredQuestion() { } public AnsweredQuestion( String question, String answer) { this.question = question; this.answer = answer; } public void setQuestion(String question) { this.question = question; } public String getQuestion() { return question; } public void setAnswer(String answer) { this.answer = answer; } public String getAnswer() { return answer; } public String toString() { return "Q. " + question + " A. " + answer; } public static void main(String[] args) throws FileNotFoundException { String filename = "qanda.xml"; AnsweredQuestion[] qAndAStore = new AnsweredQuestion[3]; qAndAStore[0] = new AnsweredQuestion( "Is an opal animal, mineral, or vegetable?", "Mineral."); qAndAStore[1] = new AnsweredQuestion( "What is the meaning of life?", "42."); qAndAStore[2] = new AnsweredQuestion( "What is your favorite color?", "Green, ..no, BLUE. AAaaaargh!"); XMLEncoder encoder = new XMLEncoder( new BufferedOutputStream( new FileOutputStream(filename))); encoder.writeObject( qAndAStore ); encoder.close(); XMLDecoder decoder = new XMLDecoder( new BufferedInputStream( new FileInputStream(filename))); AnsweredQuestion[] qAndARetrieve = (AnsweredQuestion[])decoder.readObject(); encoder.close(); for(int ii=0; ii<qAndARetrieve.length; ii++) { System.out.println( qAndARetrieve[ii] ); } }}</sscce>This probably does not do what you need, butfurther questions might require some more efforton your part, or a consultant or help-desk.Note that c.l.j.programmer is neither of the last two.Note that I have not been following the thread closelyenough to ensure this is sample code according towhat Lew was saying. I just churned it out becauseI'm *extremely* bored.-- Andrew Thompsonhttp://www.athompson.info/andrew/Message posted via JavaKB.comhttp://www.javakb.com/Uwe/Forums.aspx/java-general/200704/1
|
|
0
|
|
|
|
Reply
|
Andrew
|
4/14/2007 4:34:14 PM
|
|
John wrote:> If for a question the object type you use is String, how can you organize > the hierarchy of the all those types questions?> > My design is that there should be a abstract question class, with subclass > such as mutiple choice, matching, short answers, true/false etc.> > True/false can be the subclass of multiple choice.That's fine. There are a zillion ways to solve the problem.I see that what you mean by a question is an organization of the information. I'd probably separate the issue of whether something is implemented via checkboxes or a multi-select from the content of the information, similarly to how Swing and JSF do it.There are structures to hold the information. One example isMap< String, List<String>>that can hold the question text and the list of answers (as for multi-select), initially length 0 for unanswered questions.The presentation of the text would be handled by separate layout components.But your way seems OK, too.-- Lew
|
|
0
|
|
|
|
Reply
|
Lew
|
4/14/2007 7:24:37 PM
|
|
"Lew" <lew@nospam.lewscanon.com> wrote in message news:a-ydnYRI_rDrt7zbnZ2dnUVZ_uuqnZ2d@comcast.com...> John wrote:>> If for a question the object type you use is String, how can you organize >> the hierarchy of the all those types questions?>>>> My design is that there should be a abstract question class, with >> subclass such as mutiple choice, matching, short answers, true/false etc.>>>> True/false can be the subclass of multiple choice.>> That's fine. There are a zillion ways to solve the problem.>> I see that what you mean by a question is an organization of the > information. I'd probably separate the issue of whether something is > implemented via checkboxes or a multi-select from the content of the > information, similarly to how Swing and JSF do it.>> There are structures to hold the information. One example is>> Map< String, List<String>>>> that can hold the question text and the list of answers (as for > multi-select), initially length 0 for unanswered questions.>> The presentation of the text would be handled by separate layout > components.>> But your way seems OK, too.I think that it is possible to have another field and corresponding method to log suryvery result.What do you think?John>> -- > Lew
|
|
0
|
|
|
|
Reply
|
John
|
4/14/2007 9:53:50 PM
|
|
|
11 Replies
184 Views
(page loaded in 0.113 seconds)
Similiar Articles: File locking (Linux) - comp.unix.programmerSimple file locking would probably also do, that is, create a lock file ... Is it possible to put several objects into one file? - comp.lang ... linux shared memory ... How to hide schema and table structure for other user ? - comp ...Is it possible to put several objects into one file? - comp.lang ..... the hard drive, which can latter be retrieved by other user ... You may need to learn XML Schema ... how to properly audit generic user accounts - comp.unix.solaris ...Is it possible to put several objects into one file? - comp.lang ... I am designing a generic survey/test taking system. ... drive, which can latter be retrieved by other ... Function definition inside a script - comp.soft-sys.matlab ...... It is possible to have multiple functions in 1 m-file. ... script m-file? No, no no. You cannot put ... It is not possible to toss a bunch of functions into one file ... Object (de)serialization - comp.lang.c++... to write the contents of a set of classes to a file in ... can create an object (or several objects) and save them to a file. ... problems inserting OLE Draw objects into ... FIFO file objects - comp.unix.programmerI have one program ... much larger - if possible. It's typically compiled into the ... FIFO file objects - comp.unix.programmer As you can see, it's possible that the first ... SQL 2008 Enterprise - Deny access to database for even ...I want to lock down 'A' so that no one, not ev... ... Although it would probably be easier to put objects in B ... I can deny the access to downloading the file and ... SystemVerilog - building multiple file hierarchies: include or ...... package into multiple files ... acceptable to put more than one package, module or whatever in a single file. ... them all into a single package. And you have only one file (the ... Calling MATLAB from Visual Studio in a C program - comp.soft-sys ...... is possible to debug in VS without using Matlab because you can't pass Matlab objects into/out of your mex file ... to set up VS to do so, look at the mex batch file ... is one ... trouble Inserting OLE objects into drawings - comp.cad.solidworks ...When I try to insert an OLE object from file into my ... John B johnbogie btinternet.com Put the "at" in ... topic • Fabriwin OLE problem I can select the objects one ... Non-global zone as DHCP client? - comp.unix.solaris... feature) to put the same > VLAN on a given physical interface into multiple ... it will be possible to put multiple ... Zones on ZFS file system. - comp.unix.solaris One ... Combine multiple figures (.fig) with subplots into one figure ...... Copy the gu_ax to new fig set(P ... Combine ... multiple lines into one ... records in a ... 2 (12/15/2003 5:35:02 PM) Is it possible to merge two figures into one ... Importing "Layouts" From Different FMP docs... - comp.databases ...I am looking to join several filemaker pro files ... forms that i made for the different files into one master file ... do this immediately after pasting the layout objects. Redirect command output to a variable - comp.unix.programmer ...... unless you use (1) a temporary file for one direction ... Is it possible to sort a CSV file using command? - comp.os.linux ... ... way to redirect the result from a command into ... vertical cell concatenation - comp.soft-sys.matlabCONCATENATE the contents of cell VERTICALLY - Excel Help Forum is it possible to concatenate the contents of several cell vertically into a single cell? like using (e.g ... Inserting Multiple Picture Objects at One Time - Word 2007... all objects I wanted to bring in, and they would drop into my Word file ... Multiple Picture Objects at One Time ... > > set > > to "Top and Bottom" the picture objects come in ... Merge multiple presentations into one - PowerPoint - Office.comThere are times when you might want to combine multiple presentations into a ... the dialog box, click Add to Favorites under the File box. To display slides from one of ... 7/13/2012 2:54:17 PM
|