私はいくつかの方法でJavaプログラムを実装しました。次に、単語を入力して関連するメソッドを呼び出すメインクラスを作成しました。例えばすべてのコマンドを一度に入力できますか?
:私が欲しいもの
Enter {A|B|C|D|E} to call method. A=method one B = method two...etc
A<--this is the user input
Enter Number:<--the first Scanner input of method A
123<--Input 1
Enter words:<-- the second Scanner input of method A
ABC<--Input 2
123ABC<--The output method A
Enter {A|B|C|D|E} to call method. A=method one B = method two...etc
B<--this is the user input
Enter Number 1:<--the first Scanner input of method B
100<--Input 1
Enter Number 2:<-- the second Scanner input of method B
50<--Input 2
150<--The output method B
Code of Method A {
String output;
private static Scanner keyboard = new Scanner(System.in);
System.out.println("Enter Number:");
String no = keyboard.nextLine();
System.out.println("Enter Words:");
String words = keyboard.nextLine();
//do something...
System.out.println(output);
}
Code of Main class{
private static Scanner keyboard = new Scanner(System.in);
public static void main(String[] args){
Main main = new Main();
main.run();
}
public void run() {
boolean running = true;
while (running) {
displayMenu();
String command = keyboard.nextLine();
String[] parts = command.split("^");
if ("A".equalsIgnoreCase(command)) {
//call method A
} else if ("B".equalsIgnoreCase(command)) {
//call method B
} else if....etc
System.out.println();
}
一度
123、ABC
B
100,50入力
で、システムはメソッドA(123ABC)の出力を印刷し、 B(150)私のために。私が欲しいもの
は、私はそれをどのように行うことができます一度
で「言葉」の中に「キーボード」、「なし」に入力123と入力ABCへの入力Aのですか?
私の回答が役に立ちましたと思いますが、今後はさらに具体的な質問をすることをお勧めします。あなたの明白な質問は、答えが "はい"である "それは可能です"です。しかし、実用的なソリューションを実装するために欠けているものが何であるかわからないため、コード全体を作成したいと思っている人を見つけるのは難しいでしょう。 – Aaron
あなたの答えに感謝します。私はより具体的に私の質問を変更しました –