As you can see, these are my three classes I use for this program .. I can not find the way to let me return the two parameters in the sentence even if I do not write the keyword that I have in the array .. i would like to find the way i allow me to write input: "From roma to milano" or "to roma da milano" and have reset the parameters as they are in the code I have already developed .. according to you it is possible to achieve this, in addition to what already does the code which I have proposed to you in vision? Thanks for the attention, and for the time spent for me. Good day !
package eubot.controller;
import eubot.dictionary.EubotDictionary;
public class EubotController {
public EubotDictionary getDictionary(String stringInput) {
EubotDictionary dictionary = null;
String found = null;
for (String string1 : EubotDictionary.keyWord) {
if (stringInput.contains(string1)) {
dictionary = new EubotDictionary();
dictionary.setTesto(stringInput);
System.out.println("the string contains : " + string1);
found = string1;
String splittable = stringInput.substring(stringInput.indexOf(found) + found.length(),
stringInput.length());
// System.out.println(splittable);
for (String string2 : EubotDictionary.parameter) {
if (splittable.contains(string2)) {
dictionary = new EubotDictionary();
dictionary.setTesto(splittable);
found = string2;
String splittable1 = string2.valueOf(string2);
System.out.println("the parameters are : " + splittable1);
}
}
break;
}
}
return dictionary;
}
public EubotDictionary findParametro(String stringInput) {
EubotDictionary dictionary = null;
for (String string2 : EubotDictionary.parameter) {
if (stringInput.contains(string2)) {
}
dictionary = new EubotDictionary();
dictionary.testo = stringInput;
}
return dictionary;
}
}
package eubot.dictionary;
public class EubotDictionary {
public String testo;
public String getTesto() {
return testo;
}
public void setTesto(String testo) {
this.testo = testo;
}
public static String[] keyWord = { "devo andare", "voglio andare", "vorrei andare", "devo recarmi"};
public static String[] parameter = { "bari", "roma", "milano", "pisa", "firenze", "napoli", "como", "torino" };
public static String[] req;
}
package eubot.test;
import java.util.Scanner;
import eubot.controller.*;
import eubot.dictionary.*;
public class Test {
public static void main(String[] args) {
System.out.println("<<-|-|-|-|-|-|-|-|-|<<<Welcome In EuBot>>>|-|-|-|-|-|-|-|-|->>");
EubotController controller = new EubotController();
Scanner input = new Scanner(System.in);
String string;
while (true) {
string = input.nextLine();
EubotDictionary dictionary = controller.getDictionary(string);
}
}
}
Based on your comment:
public class EubotController {
private String[] parameter = { "bari", "roma", "milano", "pisa", "firenze", "napoli", "como", "torino" };
public void processInputString(String inputString) {
String[] input = inputString.split(" ");
boolean prefixPrinted = false;
for (String i : input) {
for (String p : parameter) {
if (i.equals(p)) {
if(!prefixPrinted) {
printPrefix(inputString, p); //call when the first parameter is found
prefixPrinted = true;
}
System.out.println("The parameters are: " + p);
}
}
}
}
private void printPrefix(String inputString, String parameterAfterPrefix) {
String prefix = inputString.substring(0,
inputString.indexOf(parameterAfterPrefix)).trim();
System.out.println(prefix);
}
}
I renamed getDictionary, so you need to call now controller.processInputString(string)
in your main
-method.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.