2017-08-09 2 views
-3

これはこれまで私の研究室で行ってきたことですが、多くのエラーが続いています。私は間違って何をしているのかわからない、誰かが私を助けてください。質問は私たちがクラスで解決しなければならないコードコメントにありますが、私の先生は助けにはなりません。これは非常にイライラ取得あなたはperformOperation(へ引数を渡す必要がありますJavaクラスの元に戻す人気度の高い大学のラボ

import java.util.Scanner; 
import java.io.FileInputStream; 
import java.io.IOException; 
import java.util.Stack; 

/** 
* Application to demonstrate the use of a stack by simulating an editor's un/redo operations. 
* 
* @author lynda 
*/ 
public class UndoRedo { 

    public static Scanner openFile(String fileName) throws IOException{ 
     Scanner fileStream; 
     FileInputStream fileByteStream = new FileInputStream(fileName); 
     return(new Scanner(fileByteStream)); 
    } 

    public static void performOperation(String operation) { 
      System.out.println("Operation: " + operation + " completed."); 
    } 

    public static void main(String[] args) throws Exception { 
     String fileName; 
     Scanner inputFileStream; 

     Stack <String> undo= new Stack<String>(); 
     Stack <String> redo= new Stack <String>(); 
     /* Declare two stacks here: one for the undo and one for the redo 
     */ 

     String operation; 

     Scanner keyboard = new Scanner(System.in); 
     System.out.print("Enter file name: "); 
     inputFileStream = openFile(keyboard.nextLine()); 

     while (inputFileStream.hasNextLine()) { 
      operation = inputFileStream.nextLine(); 

      if(!operation.equals("UNDO")|| operation.equals("REDO")){ 
       performOperation(); 
       done.push(operation); 
      } 
      else if(operation.equals("UNDO")){ 
       performOperation("undo"); 

      } 
      else if(operation.equals("REDO")){ 
       performOperation("redo"); 

      } 
      else{ 
       System.out.println("the Stack is empty"); 
      } 

      /* if we have an editor operation (i.e. anything other than UNDO or REDO) 
       then 'perform' the operation by calling the method performOperation and 
       push the operation onto the 'done' stack. 
       . 
       if we have an UNDO operation, then if there is something to undo, 
       pop it off the stack, undo it (by calling method performOperation with "undo" in the string) 
       otherwise tell the user there is nothing to undo (i.e. the stack is empty) 

       if we have a REDO operation, then if there is something to redo, 
       pop it off the stack, redo it (by calling method performOperation with "redo" in the string) 
       otherwise tell the user there is nothing to undo (i.e. the stack is empty) 
      */ 


     } 

    inputFileStream.close(); 
    } 
} 
+2

に応じてその動作を実行する必要があります。 _何らかのエラー?_ [ask]を確認してください。 – jmoerdyk

+1

'performOperation()'のためのメソッドはありません。パラメータなしで 'else if(operation.equals(" REDO "))'はこのロジックで決して入力されません –

+0

ここに遭遇したエラーを投稿すれば、それぞれを解決する方法をあなたに教えてください。 –

答えて

-1

をこれを理解しようとしている費やした時間をアイブ、誰か私を助けてください) と私はあなたのコード で行うと呼ばれる任意のスタックが表示されないされ、 performOperation方法は、「私は多くのエラーを得続ける」その中にプッシュとポップを持っているし、あなたの文字列引数

if(!operation.equals("UNDO")|| operation.equals("REDO")){ 
       *performOperation();* 
       done.push(operation); 
      } 
+0

どのようなarg私は操作を実行するために渡す必要がありますか? – Karanvir1

+0

あなたはargsのないperformメソッドを持っていないので、正しいオプションを入力するように再度頼むべきです –

関連する問題