Results 1 to 4 of 4
  1. #1
    Join Date
    Jul 2010

    Question DTree Database help

    Ok, so im a new guy at this. I have already made a game that is like 20 questions that uses a decision tree that requires yes or no answers to guess the animal you were thinking. However, the database does allow for additions to it if at the end of the game the computer answered wrong, but it does not allow you to edit it outside of the game. What I am wanting to do is edit the program so that it troubleshoots computer problems for teachers at a local high school still using yes or no answers, and I have that part down. But I am not quite sure how to change the database into a file that it will read that I can go into and edit whenever I want. Can anyone help me with this? If so I would be very grateful!
    Last edited by newbe; 07-23-10 at 16:05.

  2. #2
    Join Date
    Feb 2004
    In front of the computer
    That sounds like a programs called "Animals" that was popular in the 1970s. It was often a student's first introduction to data files.

    The version of the "Anmials" program that I remember was written in BASIC and it used random access data files to hold the question, another record number to use if the response was yes, and another record number to use if the answer was no. If the response led to record 0 then the program knew it had to get a new question to distinguish between its guess and the user's answer and then add those rows to the file.

    What language does your program use? What kind of storage does your program use? Are you sure that you want to limit the questions to just "Yes" and "No" responses?

    In theory, theory and practice are identical. In practice, theory and practice are unrelated.

  3. #3
    Join Date
    Jul 2010
    Yup thats what it was for, a into class into java. I am a first year comp sci student. However, it wasnt a random acces data file. It is built as a binary tree, and a yes answer follows the tree to the left and no answers to the right. And when it sees that it is the last node it guesses whatever data is set for that node. I am using Java, and when you start the prog it looks for the DB and if the correct one is not found then it creates a new one. After one is created it plays the game, and at the end of the game, if the game guesses an incorrect answer the user can add new info to the bottom to the tree. And yes, I am wanting to keep it simple with yes and no answers, but I am also possibly incorporating "ok" answers for a few situations (and they basically act as yes answers in the prog but makes it more simple for the teacher users). And I already have that worked out. But what I am wanting is to be able to have a DB that I can create tree structure in a text file or something and be able to go in later and edit it, but not really sure how.

  4. #4
    Join Date
    Jul 2010
    This is what I have right now:

    // LOAD DATABASE -----------------------------------------------------------------------------------

    static DTree loadDB(String filename){
    // pre: there is an troubleshootlDB database
    /* post: loads troubleshootDB database
    if troubleshootDB is not found, one is created*/

    FileInputStream fis = new FileInputStream("troubleshootDB.db");
    ObjectInputStream in = new ObjectInputStream(fis);
    DTree db = (DTree) in.readObject();
    return db;
    catch(Exception e){
    System.out.println("File troubleshootDB could not be found, a new file will be created.\n");
    return new DTree("Please add an issue to SchoolDude");

    // SAVE DATABASE -----------------------------------------------------------------------------------

    public static void saveDB(String filename, DTree db){
    // pre: there is an troubleshootDB database
    // post: saves troubleshootDB database

    FileOutputStream fos = new FileOutputStream("troubleshootDB.db");
    ObjectOutputStream out = new ObjectOutputStream(fos);
    catch(IOException e){
    System.out.println("Error writing object to file");

    // SAVE GAME ---------------------------------------------------------------------------------------

    public static void saveGame(Boolean answer, DTree db){
    // Must receive an answer and the DTree

    if(answer == true){
    saveDB("troubleshootDB.db", db);

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts