2014-11-08 5 views
-4

askCalcChoice1 외에도 모든 것이이 계산기에서 올바르게 작동합니다. askCalcChoice1은 문자열이므로 잘못된 (분명히) 호출합니다. 오류는 문자열을 int로 변환 할 수없고 int를 부울로 변환 할 수 없다고 말합니다. 그러나 inputOperation을 문자열로 만들면 askCalcChoice1 아래의 다른 두 개의 호출이 중단됩니다. (문자열이 아니기 때문에 displayRedults와 askTwoValues가 깨집니다). 어떻게 다른 클래스 wihtout 작성된이 메서드를 호출하려면 askCalcChoice 서식을 방법을 모르겠다. askCalcChoice는 oopCalculator 코드 아래에 붙여 넣은 문자열로 작성됩니다. 어떤 방법이 있습니까 누군가 나를 oopCalculator에서 해당 코드의 해당 부분을 작성하는 방법을 보여주십시오 수 있습니까?Console Calculator error java

int inputOperation; // user to choose the function 
    askCalcChoice1 myAskCalcChoice1 = new askCalcChoice1(); 

    //menu becomes a complete string below 
    String menu = "Welcome to Hilda Wu's Calculator\t\t" 
      + "\n1. Addition\n" 
      + "2. Subtraction\n" 
      + "3. Multiplication\n" 
      + "4. Division\n" 
      + "5. Exit\n\n"; 
    calculatorCommands.pickNewSymbol(menu); //complete menu will be picked up as a string and display 
    calculatorCommands.putDownSymbol(); 

    while (inputOperation = myAskCalcChoice1.calcChoice()) { //this will call for myAskCalcChoice1 class 
     calculatorCommands.pickNewSymbol("\n"); //pick up the class 
     calculatorCommands.putDownSymbol(); //display the class 

     askTwoValues myAskTwoValues = new askTwoValues();   
     float[] myFloats = myAskTwoValues.inputFloats(inputOperation); 


     displayResults myDisplayResults = new displayResults(); 
     float result = myDisplayResults.showResults(inputOperation, myFloats); 

     String strFormat = "The answer is: " + result + "\n\n"; //print out The answer is as a string 
     calculatorCommands.pickNewSymbol(strFormat); //pick up string from above 
     calculatorCommands.putDownSymbol(); //display string 
     calculatorCommands.pickNewSymbol(menu); // pick up menu from the beginning of code, loop to calculator menu 
     calculatorCommands.putDownSymbol(); //display menu as loop 
    } 
    calculatorCommands.pickNewSymbol("\nThank you for using Hilda Wu's Calculator\n"); //when user choose to exit calculator 
    calculatorCommands.putDownSymbol(); 
} 






String calcChoice() { 
    String input; 
    do { //do loop will continue to run until user enters correct response 
     System.out.print("Please enter a number between 1 and 5, A for Addition, S for Subtraction, M for Multiplication, or D for Division, or X for Exit: "); 
     try { 
      input = readInput.nextLine(); //user will enter a response 
      if (input.equals("A") || input.equals("S") || input.equals("M") || input.equals("D") || input.equals("X")) { 
       System.out.println("Thank you"); 
       break; //user entered a character of A, S, M, or D 
      } else if (Integer.parseInt(input) >= 1 && Integer.parseInt(input) <= 5) { 
       System.out.println("Thank you"); 
       break; //user entered a number between 1 and 5 
      } else { 
       System.out.println("Sorry, you have entered an invalid choice, please try again."); 
      } 
      continue; 
     } 
     catch (final NumberFormatException e) { 
      System.out.println("You have entered an invalid choice. Try again."); 
      continue; // loop will continue until correct answer is found 
     } 
    } while (true); 
    return input; 
} 

}

+0

나는 질문을 놓쳤다. – csmckelvey

+0

문제의 진술은 어디에 있으며 어디에서 붙어 도움이 필요합니까? – mattias

+0

문제는 주 계산기 프로그램에서 정의되지 않은 오류가 발생하고 있다는 것입니다. 아래쪽 코드 조각에서 switch 메서드를 호출하는 데 문제가 있습니다. 명령문의 형식을 지정하여 스위치를 호출하는 방법을 모르는 경우 method.askCalcChoice1 myAskCalcChoice1 = new askCalcChoice1(); while ((inputOperation = myAskCalcChoice1.userInput())! = 5) – userQuestion

답변

0

, 당신은 두 개의 인수 showResults를 호출하여 시작하려면 : 및 플로트 [] F

선택은 사용되지 않습니다 INT 선택. 스위치에서 대신 입력 변수를 사용하지만 기본적으로 선택 사항을 나타내는 오류를 반환합니다.

함수의 인수로 선택 항목을 전달하는 것이 좋으며 다른 유형이 아닌 char이어야합니다.

또한 올바른 형식의 질문이 아닙니다. 나는 그것을 평가하지 않을 것이지만 전체 코드가 올바르게 표시되도록 다시 작성하십시오. 나는 그것을 쉽게 이해할 수 없다. 나는 이미 그것을 오해 할 수도있다. 사이에 주석을 추가하지 말고 정확한 들여 쓰기를하고 코드를 모두 입력했는지 확인하십시오. 나중에 주석을 작성해야하는 경우. 그다지 복잡하지는 않습니다. 나중에 코드를 보여주고 나중에 잘못을 묻는 것입니다.)

선택 사항이 스위치를 전달하려는 경우 ... int가 아닌 char이지만 전달하십시오.