• Post Reply Bookmark Topic Watch Topic
  • New Topic

Say hello to the Oracle  RSS feed

 
Ahmad Auada
Ranch Hand
Posts: 56
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Wazzup you guys!
I have been teaching myself java for about a few months now, and for a few days I was working on this little program. You can ask it any question, and it answers. If you ask it a question that it does not have an answer for, it asks you for an answer which it then adds to a database. The next time you ask it that question, it would know the answer. It just keeps expanding it self the more you use it.

I still haven't learned how add some GUI to my program, but I thought you guys might wanna take a look!

create 2 classes, test and test2, and a txt file called "file". then run it in eclipse.

/////////////////////////////////////////////////////test///////////////////////////////////////////////////////////////////////////////////



////////////////////////////////////////////////////test2////////////////////////////////////////////////////////////////





///////////////////////////////////////////////////////////////////////file.txt////////////////////////////////////////////////////////////////////////////////

#What is your name?:My name is oracle$
#What is the meaning of life?:It's 42$
#what are you?:I am an oracle... I know.. everything.$^

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

waiting for your comments! =)


 
Knute Snortum
Sheriff
Posts: 4087
112
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
* Class Names: All class names should start with an uppercase letter and should have meaningful names. "test2" should probably be called Oracle.

* Method Names: All method names should start with a lowercase letter.

* Repeated Code: You have a chunk of code that pauses for two seconds scattered all over your code. Better would be to create a method called pause(), maybe also with a parameter of the number of second to pause.

* Access Modifiers: You should add access modifiers to all fields and methods. All fields should be private. Methods should be public only if they have to be.

There will be more as I dig into the code further.
 
Campbell Ritchie
Marshal
Posts: 55772
163
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
…and even after your improvements, the indentation is barely adequate for people to read that code.
 
Knute Snortum
Sheriff
Posts: 4087
112
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

I'm not sure why this code is in the class "test". If "test" is a class to run and test your code, that's all it should do.


This code is hard to read and is error prone. The indentation should be corrected to show what statements are under the control of the do and if blocks. You should always use braces on if statements, even if they have only one line. The if/else/if structure you have is very prone to errors because it's hard to see what controls what. As an example, the above code should look more like this:

This can be applied throughout the code.
 
Ahmad Auada
Ranch Hand
Posts: 56
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the tips! =)
 
J. Kevin Robbins
Bartender
Posts: 1801
28
Chrome Eclipse IDE Firefox Browser jQuery Linux MySQL Database Netbeans IDE
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you post code here, you can expect it to get nit-picked. Don't think of it as criticism but rather opportunities to become a better programmer.

In addition to the tips already listed, what jumps out at me is that you have too much code in the main method. It should be just one or two lines. Use it to instantiate an instance of the program and call some sort of run() method.
 
Michael Scalzetti
Greenhorn
Posts: 20
Java Ubuntu Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If I want to run this where should I put the file.txt (I'm using Luna Eclipse), it would have been nice if you had instructions for this...
 
Knute Snortum
Sheriff
Posts: 4087
112
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would try putting the "file.txt" in the top of the project folder.
 
Ahmad Auada
Ranch Hand
Posts: 56
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Michael Scalzenni wrote:If I want to run this where should I put the file.txt (I'm using Luna Eclipse), it would have been nice if you had instructions for this...


Just create a file in the src folder (or just do what knute said) , name it file, then copy the contents that I wrote above into your file.
Don't forget to tell me if you like it =)
 
salvin francis
Bartender
Posts: 1612
36
Eclipse IDE Google Web Toolkit Java
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ahmad Auada wrote:Wazzup you guys!
I have been teaching myself java for about a few months now, and for a few days I was working on this little program. You can ask it any question, and it answers. If you ask it a question that it does not have an answer for, it asks you for an answer which it then adds to a database. The next time you ask it that question, it would know the answer. It just keeps expanding it self the more you use it.


All the best for your program. I have made something similar, I called her sally. But i made the worst mistake of putting sally online. People starting teaching her to abuse so I turned off her learning logic.
An input for your, instead of a direct comparison, try using some fuzzy logic.

Your program is a bit cryptic to read, as others have pointed. A few variables like ui, cube make no sense to me. Even methods like rui,addQ,Qnotfound are cryptic to read. They will be meaningless to you as well if you read this same program after 3-4 years.


You can see my program here : http://salvin.in/sally/
 
Ahmad Auada
Ranch Hand
Posts: 56
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
salvin francis wrote:
Ahmad Auada wrote:Wazzup you guys!
I have been teaching myself java for about a few months now, and for a few days I was working on this little program. You can ask it any question, and it answers. If you ask it a question that it does not have an answer for, it asks you for an answer which it then adds to a database. The next time you ask it that question, it would know the answer. It just keeps expanding it self the more you use it.


All the best for your program. I have made something similar, I called her sally. But i made the worst mistake of putting sally online. People starting teaching her to abuse so I turned off her learning logic.
An input for your, instead of a direct comparison, try using some fuzzy logic.

Your program is a bit cryptic to read, as others have pointed. A few variables like ui, cube make no sense to me. Even methods like rui,addQ,Qnotfound are cryptic to read. They will be meaningless to you as well if you read this same program after 3-4 years.


You can see my program here : http://salvin.in/sally/


Thank you for the tip, salvin!
I love your program!

It gave me some strange answers, though

-why is the sky blue?
-i am 23 years old

hmm.. but it seems that the answers are not just random. I would love to know how you programmed it!


 
Ahmad Auada
Ranch Hand
Posts: 56
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
salvin
I just had an idea

maybe you can reprogram it so that YOU write the answers
so when someone asks it a question it does not have an answer for, it would just say something like "i dont know", and then notify to write a reply to be set for that question.

would loose the "self expanding " part but I think it would solve the problem!


 
salvin francis
Bartender
Posts: 1612
36
Eclipse IDE Google Web Toolkit Java
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes I too had that in mind about prompting user for an answer.
[Edit] Interesting, I first misunderstood what you wrote. I'll take this as an input.

My current algorithm does a percentage match based on an algorithm I wrote.
If this percentage is greater than a given threshold, it treats it as a match. A low threshold (say 20) will give vague answers and a high threshold (say 80%) will match only a few questions.

I took the help of a few friends to test to figure out what should be a good threshold value.

Because of this threshold concept, the program gets more intelligent as it learns more. So for example if a user taught it an answer to a given query with 80% match, another user may teach a more similar question with 90% match
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!