控制台计算器错误java

控制台计算器错误java,java,Java,因此,除了ASKCalChoice1之外,这个计算器的一切都很好。因为askcalchoice1是一个字符串,我显然把它称为错误的。该错误表示它无法将字符串转换为int,也无法将int转换为布尔值。但是,当我将inputOperation设置为字符串时,它会中断下面的其他2个调用AskCalChoice1。它会中断displayRedults和AsktwoValue,因为它们不是字符串。我不知道如何格式化askcalchoice,以便调用在另一个类中编写的方法,而不破坏任何内容。AskCalCh

因此,除了ASKCalChoice1之外,这个计算器的一切都很好。因为askcalchoice1是一个字符串,我显然把它称为错误的。该错误表示它无法将字符串转换为int,也无法将int转换为布尔值。但是,当我将inputOperation设置为字符串时,它会中断下面的其他2个调用AskCalChoice1。它会中断displayRedults和AsktwoValue,因为它们不是字符串。我不知道如何格式化askcalchoice,以便调用在另一个类中编写的方法,而不破坏任何内容。AskCalChoice是作为字符串编写的,我将它粘贴在oopCalculator代码下面。有没有办法,有没有人能告诉我如何在oopCalculator中编写这部分代码

    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;
}

}

首先,您使用两个参数调用showResults: 整数选择 和 浮动[]f

选择永远不会被使用。 在开关中使用输入变量,但在默认情况下,返回显示选项的错误

最好将选项作为参数传递到函数中,并确保它是char而不是其他类型

而且,这不是一个好的陈述问题的形式。我不会降低它的评级,但请重新制作,使整个代码正确显示。我不容易理解它。我可能已经误解了。请不要在两者之间添加注释,请确保缩进正确,并且所有代码都已输入。 如果您需要评论,请稍后再评论。这并不复杂,只要给我们看一下代码,然后问出什么问题


如果选择是为了通过开关。。。然后做,但不要像int那样做,而是像char那样做。

我错过了这个问题。问题陈述在哪里?你在哪里卡住了,需要帮助?问题是我在主计算器程序中遇到了一个未定义的错误。从代码的底部片段调用switch方法时遇到问题。不知道如何格式化语句以使其调用switch方法。askcalchoice1 myaskcalchoice1=new askcalchoice1;而inputOperation=MyAskCalChoice1.userInput!=5Java非常善于告诉您错误。Java给了您什么样的错误?好的,那么这就是您应该寻求帮助的地方。不多。请告诉我们有关此未定义错误的更多信息。这是某种例外吗?如果是,请包括stacktrace等。