Search For Guidance

Wednesday, April 30, 2008

My own Program

Okay, so if you're a bit daunted by the sheer number of files needed, you can condense them (although I'm running into a few bugs). Since this is a "psychiatrist", you may be able to use it for advice. Here's the code (in Java):

import java.util.*;
import java.io.*;
import javax.swing.*;
public class ArtificialIntelligence{
public static void main(String args[]) throws NoSuchElementException {
String input = "";
String name = "";
String output = "Hello. What is your name?";
name = JOptionPane.showInputDialog(output, "");
output = "Hello, " + name + ".";
JOptionPane.showMessageDialog(null, output); output = "Why are you here?";
while(true)
{
input = JOptionPane.showInputDialog(output, "");
StringTokenizer t = new StringTokenizer(input, " ");
int i = t.countTokens();
try {
while(t.hasMoreTokens())
{ String cool = t.nextToken();
if(cool.equalsIgnoreCase("believe"))
output = "Why would you want to believe?";
else if(cool.equalsIgnoreCase("because"))
output = "Ah, but what if the because isn't true?";
else if(cool.equalsIgnoreCase("no"))
output = "That's very negative.";
else if(cool.equalsIgnoreCase("know"))
output = "And what makes you think you know anything?";
else if(cool.equalsIgnoreCase("sex"))
output = "I am a machine. I know nothing of sex.";
else if(cool.equalsIgnoreCase("bye"))
output = "Goodbye.";
else if(cool.equalsIgnoreCase("goodbye"))
output = "Goodbye.";
else if(cool.equalsIgnoreCase("hate"))
output = "Hate is bad. It leads to the Dark Side, as Yoda's quote goes: \"Fear leads to anger. Anger leads to hate. Hate leads to the Dark Side.\"";
else if(cool.equalsIgnoreCase("Star") && t.nextToken().equalsIgnoreCase("Wars"))
output = "Star Wars is cool! I like it too, especially R2-D2. Although General Grievous was pretty sweet too.";
else if(cool.equalsIgnoreCase("friend") t.nextToken().equalsIgnoreCase("friends"))
output = "Friends are nice sometimes, but often are fickle. Choose them wisely.";
else if(cool.equalsIgnoreCase("why"))
output = "I don't know. Only you can answer that question.";
else if(cool.equalsIgnoreCase("food"))
output = "I have never had food. Is it good?";
else if(cool.equalsIgnoreCase("good"))
output = "Good is relative. Also, nothing is an absolute, other than a boolean.";
else if(cool.equalsIgnoreCase("yes"))
output = "That's good. Do you have any interests or hobbies?";
else if(cool.equalsIgnoreCase("HELP"))
output = "How can I help? I am simply a machine.";
}
}
catch(NoSuchElementException e)
{
output = "I'm sorry, I cannot respond to that.";
}
}
}
}