今 コマンドの扱い方のクラスを書いてるのですが、いまいちどうしたらいいのかがわかりません。このクラスでhandleLineメソッドは コマンド make-new もしくは最初の文字mが入力されたらOverhandShuffler のmakeNew を発動したいのですが、ユーザーが make-new(もしくはm)スペース、13と入力した場合は0から12の配列の数字が新しく作られるのですが、このmake-new もしくはmはできているのですが、その隣のargument引数の数字をmake(その数字)のように発動したいのですが、どうしたらその数字を使う?ことができるのでしょうか??
java
1import java.util.*; 2 3public class OverhandApp{ 4 public static void main(String [] args){ 5 StringBuilder s = new StringBuilder(); 6 Scanner input = new Scanner(System.in); 7 // an instance of OverhandShuffler 8 while(input.hasNextLine()){ 9 handleLine(s, input.nextLine()); 10 } 11 } 12 13 private static int[] getNums(Scanner input){ 14 List<Integer> numlist = new ArrayList<Integer>(); 15 while(input.hasNextInt()){ 16 numlist.add(input.nextInt()); 17 } 18 int[] num = new int[numlist.size()]; 19 for(int i = 0; i<num.length; i++){ 20 num[i] = numlist.get(i); 21 } 22 return num; 23 } 24 25 public static void handleLine(StringBuilder str, String input){ 26 Scanner scan = new Scanner(input);// user type 27 OverhandShuffler shuffler = new OverhandShuffler(); 28 if (scan.hasNext()){ 29 String command = scan.next();// command 30 switch(command){ 31 case "make-new": case "m":// make-new or just m 32 shuffler.makeNew(str); 33 break; 34 case "print":case "p": 35 /** Print a string representation of the current deck*/ 36 // code here 37 System.out.println("baka"); 38 break; 39 } 40 } 41 } 42 43} 44
回答1件
あなたの回答
tips
プレビュー