在Java中的方法中找不到符号

时间:2013-11-26 00:12:13

标签: java

我在尝试计算fedtax时遇到错误。但它说它无法找到符号。我尝试了不同的东西,但我仍然得到同样的错误。任何帮助,将不胜感激。

public class calculatetax  {  
  public static void main( String[ ]  args)  {
     Scanner kb = new Scanner(System.in);
      int employeehr = 0;
      int ratehr = 0;
      String stateresidence = "";
      String maritalstatus = "";

      System.out.println( " Employee Hours pls " ) ;
      employeehr = kb.nextInt();

      System.out.println( " Hourly Rate " ) ;
      ratehr = kb.nextInt();

      System.out.println( " State of residence" ) ;
      stateresidence = kb.nextLine();

      System.out.println( "Marital Status" ) ;
      maritalstatus = kb.nextLine();

     int wages = calculatewages(employeehr,ratehr);
     calculatefedax(wages,maritalstatus); 
  }

  public static int calculatewages( int n1, int n2 ) {  
     int wages = n1 * n2;
     System.out.println("Return Wages" + wages);
     return wages;
  }    


  public static double calculatefedtax(double fedtax, str maritalstatus) {     
    if(maritalstatus.equals("marry"))
    {
    fedtax = fedtax * .20;
    }
    else if (maritalstatus.equals("single"))
    {
    fedtax = fedtax * .25;
    }
    else
    {
    fedtax = fedtax * .22;
    }
     return fedtax;

  }       
}

2 个答案:

答案 0 :(得分:1)

int wages
String maritalstatus
calculatefedax(wages,maritalstatus)

calculatefedtax(double fedtax, str maritalstatus)

你看到了问题吗?

int + String个参数没有合适的方法。 str应为String 哦,你看起来在方法名称中有一个拼写错误。这就是为什么它告诉你它无法在那条线上找到符号。

答案 1 :(得分:0)

你写了str而不是String。您也忘了导入扫描仪。最后你弄明白了fedtax但没有做任何事情。

calculatefedax(wages,maritalstatus);

这应该是

String fedtax = calculatefedax(wages,maritalstatus);

固定代码

    import java.util.Scanner;

public class calculatetax {
    public static void main(String[] args) {

        Scanner kb = new Scanner(System.in);
        int employeehr = 0;
        int ratehr = 0;
        String stateresidence = "";
        String maritalstatus = "";

        System.out.println(" Employee Hours pls ");
        employeehr = kb.nextInt();

        System.out.println(" Hourly Rate ");
        ratehr = kb.nextInt();

        System.out.println(" State of residence");
        stateresidence = kb.nextLine();

        System.out.println("Marital Status");
        maritalstatus = kb.nextLine();

        int wages = calculatewages(employeehr, ratehr);
        double fedtax = calculatefedtax(wages, maritalstatus);
        System.out.println("Fedtax:" + fedtax);
    }

    public static int calculatewages(int n1, int n2) {

        int wages = n1 * n2;
        System.out.println("Return Wages" + wages);
        return wages;
    }

    public static double calculatefedtax(double fedtax, String maritalstatus) {

        if (maritalstatus.equals("marry")) {
            fedtax = fedtax * .20;
        } else if (maritalstatus.equals("single")) {
            fedtax = fedtax * .25;
        } else {
            fedtax = fedtax * .22;
        }
        return fedtax;

    }

}
编辑:正如Jeroen Vannevel指出的那样,我完全错过了你忘记了你的时间

calculatefedax(wages,maritalstatus);