mardi 17 avril 2018

Arraylist with if statements

I am tasked with creating a simple Turing Test using ArrayLists. I know how to create the ArrayLists, but I'm having trouble connecting them to the if statements to respond properly to the user input. An example of this issue is below. When the user inputs Frank I want the first response, and any other input should result in the other response. However, whatever tweaks I make just make one or the other show up no matter what I input.

ArrayList<String> names = new ArrayList<String>();

    names.add( "Frank" );

System.out.print( "Hello, what is your name? ");
    names.add(scanner.next());

    if( names.contains( "Frank" )) {
        System.out.printf( "Nice to meet you, Frank. My name is John.\n" );
    }
    else {
            System.out.printf( "What an interesting name. My name is John.\n");
            }

Aucun commentaire:

Enregistrer un commentaire