vendredi 18 août 2017

JAVA. How to have a conversation with the user without the scanner class?

So I have to create a small chatterbot that asks the user questions and then assess what the user has said and asks more questions, and I am unable to make use of the scanner class, which makes validating the user input somewhat trickier. I also cannot use the return, break, or continue statements.

Basically I've got 10 variables for topics of conversation, and I need to find a way I can ask the user if any of these topics interest them, and then ask a question about the topic before returning to the list of topics to talk about.

This is my code so far:

import javax.swing.*;

public class letsstartatthebasiclevel {
    public static void main(String[] args) {

        // String Dungeons = JOptionPane.showInputDialog("Dungeons.. I see. It is
        // rumored there are some caverns to the north that you may want to explore");
        // String Dragons;
        // String Work;
        // String Romance;
        // String Books;
        // String Gardening;
        // String Politics;
        // String Games;
        // String Music;
        // String Partying;

        JOptionPane.showInputDialog("Greetings traveller, I am Jeeves");

        String first_name;
        first_name = JOptionPane.showInputDialog("I hope you're well. What is your name?");




        boolean finished = false;
        while (!finished) {
            if (first_name.isEmpty()) { 

            first_name = JOptionPane.showInputDialog("I'm sorry I didn't quite catch that. What was your name again?");
            }
            else finished = true;

            }

        // while (first_name.equals(null)) {
        // JOptionPane.showInputDialog("I'm sorry I didn't quite catch that. What was
        // your name again?");

        // }

        JOptionPane.showMessageDialog(null, "Nice to meet you " + first_name);

        JOptionPane.showMessageDialog(null,
                "We can talk about many things, just a moment... I have a list of some topics we could talk about.. where was it..");

        String topics;

        topics = "\nDungeons\nDragons\nWork\nRomance\nBooks\nGardening\nPolitics\nGames\nMusic\nPartying";

        String first_question = JOptionPane.showInputDialog(
                "Ah! Here it is. Is there anything here that tickles your fancy? Just enter the topic you would like to talk about"
                        + topics);

            if (first_question.contains(topics)) { 

            //ask a question about the first topic the user chooses JOptionPane.showInputDialog("Okay great, what do you think about (topic they chose)");
            }
            else JOptionPane.showInputDialog("That's not something I know of unfortunately, just enter one of the topics from this list" + topics);

            // I need to find a way that I can analyze what the user has entered, and if they enter an actual topic keyword, then ask them one more question about that topic before returning to the topics list.

            //I also need some code that makes it so that if the user ever enters text with a "?" the bot will say "I'm the one doing the talking here!" 
            // also need to come up with a way to make it so that if the user types stop, the program stops. 
            }



        // String topic;

        // topic = JOptionPane.showInputDialog("Here it is!" +Dungeons );

    }
}

Aucun commentaire:

Enregistrer un commentaire