我的机器人程序接受用户输入,然后不做回复,什么都不做

时间:2018-06-01 13:01:15

标签: java

我创建了一个机器人并使用了我发明的代码片段,称为“简化”来大大缩短java命令。

唯一的问题是,我用它制作的僵尸程序不起作用。它应该搜索用户输入的关键字并相应地回复,但它真正做的就是接受用户输入,然后关闭。我做错了什么?

import java.util.*;
    public class bot{
        //"simplify" and "bot" created by @genisome, All rights reserved.
    System.out.println(in);

}



public static void print(String in){

System.out.println(in);

}



public static void print(double in){

System.out.println(in);

}



public static void print(long in){

System.out.println(in);

}



public static void print(boolean in){

System.out.println(in);

}



public static void print(float in){

System.out.println(in);

}



//scan below



public static void scan(int dumpinto){

Scanner x = new Scanner(System.in);

dumpinto = x.nextInt();

}



public static void scan(String dumpinto){

Scanner x = new Scanner(System.in);

dumpinto = x.next();

}



public static void scan(double dumpinto){

Scanner x = new Scanner(System.in);

dumpinto = x.nextDouble();

}



public static void scan(float dumpinto){

Scanner x = new Scanner(System.in);

dumpinto = x.nextFloat();

}





public static void scan(boolean dumpinto){

Scanner x = new Scanner(System.in);

dumpinto = x.nextBoolean();

}

public static void random(int min, int max, int dumpinto){
    Random x = new Random();
    dumpinto = x.nextInt(max) + min;
}

public static void main (String[] x){
int score;
String[] badcomputerresponse = {"that sucks, sorry", "sorry about that", "bummer", "shit", "aw, damn"};
String[] goodcomputerresponse = {"awesome.", "me too", "great", "cool", "I'm not bad myself"};
String[] goodwords = {"good", "fine", "dandy", "awesome", "cool", "swell", "great", "amazing", "ok", "okay", "well", "happy", "thrilled"};
String[] badwords = {"shitty", "terrible", "sad", "bad", "crappy", "terrible", "sucky", "up shit creek", "pathetic", "miserable", "badly", "terribly", "miserably"};
String input = "";
print("Hey there, how are you doing?");
scan(input);
for (int counter = 0; counter < goodwords.length; counter++){
    if (input.contains(goodwords[counter])){
        if (input.contains("not")){
            sadanswer(badcomputerresponse);
        }
        else{
            happyanswer(goodcomputerresponse);
    }
}
}
for (int count2 = 0; count2 < badwords.length; count2++){
    if (input.contains(badwords[count2])){
        if (input.contains("not")){
            happyanswer(goodcomputerresponse);
        }
        else{
            sadanswer(badcomputerresponse);
    }
}
}
}    
public static void sadanswer(String[] badcomputerresponse){
    int randomanswer = 0;
    random(0, badcomputerresponse.length, randomanswer);
    print(badcomputerresponse[randomanswer]);
}

public static void happyanswer(String[] goodcomputerresponse){
    int randomanswer = 0;
    random(0, goodcomputerresponse.length, randomanswer);
    print(goodcomputerresponse[randomanswer]);
}
}

编辑:谢谢那些给我帮助而不是低估我的人。 对那些向我投降的人来说,你很臭!

1 个答案:

答案 0 :(得分:0)

首先,您要定义一堆scan方法,如下所示:

public static void scan(String dumpinto){

Scanner x = new Scanner(System.in);

dumpinto = x.next();

}

然后你这样称呼它:

String input = "";
print("Hey there, how are you doing?");
scan(input);

该功能不会像它看起来那样。 String dumpinto是该方法的输入参数。你不能写输出。方法执行完毕后,您输入的值将丢失。致电scan(input);后,input变量仍然包含""。 (打印出来或使用调试器进行验证。)

您的scan方法需要返回一个值。更好的是,完全摆脱这些方法,只需使用一个Scanner对象来获取用户的输入。