If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > General > Database Concepts & Design > DTree Database help

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 07-23-10, 16:02
newbe newbe is offline
Registered User
 
Join Date: Jul 2010
Posts: 3
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.
Reply With Quote
  #2 (permalink)  
Old 07-23-10, 17:54
Pat Phelan Pat Phelan is offline
Resident Curmudgeon
 
Join Date: Feb 2004
Location: In front of the computer
Posts: 12,605
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?

-PatP
__________________
In theory, theory and practice are identical. In practice, theory and practice are unrelated.
Reply With Quote
  #3 (permalink)  
Old 07-23-10, 23:48
newbe newbe is offline
Registered User
 
Join Date: Jul 2010
Posts: 3
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.
Reply With Quote
  #4 (permalink)  
Old 07-23-10, 23:52
newbe newbe is offline
Registered User
 
Join Date: Jul 2010
Posts: 3
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*/

try{
FileInputStream fis = new FileInputStream("troubleshootDB.db");
ObjectInputStream in = new ObjectInputStream(fis);
DTree db = (DTree) in.readObject();
in.close();
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

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

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

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

if(answer == true){
saveDB("troubleshootDB.db", db);
}
else{
return;
}
}
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On