import java.util.Scanner;
public class Salary{
String employeeId="";
double wage=0;
static double tax=0;
double realWage=0;
public double computeTax(){
tax=Tools.computeTax(wage);
return tax;
}
public double computeRealWage(){
realWage=wage-this.computeTax();
return realWage;
}
public static void main(String[] args){
Salary salary=new Salary();
Scanner sc=new  Scanner (System.in);
System.out.println("职工号");
salary.employeeId=sc.nextLine();
System.out.println("税前工资");
salary.wage=sc.nextDouble();
System.out.println("职工号"+salary.employeeId+"税前工资"+salary.wage+"扣税"+salary.computeTax()+"实发工资"+salary.computeRealWage());
}
}
class Tools
{
final static int START_TAX=2000;
double tax;
public double computeTax(double wage)
{
if(wage-START_TAX<=0){
  tax=0;
return tax;
}
if(wage-START_TAX<=500) 
{
 tax=(wage-2000)*0.05;
return tax;
}
if((wage-START_TAX>500)&&(wage-START_TAX<=2000))
 {
 tax=(wage-2000)*0.1-25;
return tax;
}
if(wage-START_TAX>2000)
{
        tax=(wage-2000)*0.15-125;
       return tax;
}
}
}

解决方案 »

  1.   


    import java.util.Scanner;class Tools
    {
    final static int START_TAX = 2000;
    double tax; public double computeTax(double wage)
    {
    if (wage - START_TAX <= 0)
    {
    tax = 0;
    }
    if (wage - START_TAX <= 500)
    {
    tax = (wage - 2000) * 0.05; }
    if ((wage - START_TAX > 500) && (wage - START_TAX <= 2000))
    {
    tax = (wage - 2000) * 0.1 - 25;
    }
    if (wage - START_TAX > 2000)
    {
    tax = (wage - 2000) * 0.15 - 125;
    }
    return tax;// 把大括号里面的return语句去掉,直接在外面return。
    }
    }public class Salary
    {
    String employeeId = "";
    double wage = 0;
    static double tax = 0;
    double realWage = 0; public double computeTax()
    {
    tax = new Tools().computeTax(wage);// 这里没必要把此函数设置为static的。
    return tax;
    } public double computeRealWage()
    {
    realWage = wage - this.computeTax();
    return realWage;
    } public static void main(String[] args)
    {
    Salary salary = new Salary();
    Scanner sc = new Scanner(System.in);
    System.out.println("职工号");
    salary.employeeId = sc.nextLine();
    System.out.println("税前工资");
    salary.wage = sc.nextDouble();
    System.out.println("职工号" + salary.employeeId + "税前工资" + salary.wage
    + "扣税" + salary.computeTax() + "实发 工资"
    + salary.computeRealWage());
    }
    }
      

  2.   

    如果必须要这样调用的话,得这样。供楼主参考import java.util.Scanner;class Tools
    {
    final static int START_TAX = 2000;
    private static double tax;//这里要设置为static  public static double computeTax(double wage) ////这里也要设置为static 
    {
    if (wage - START_TAX <= 0)
    {
    tax = 0;
    }
    if (wage - START_TAX <= 500)
    {
    tax = (wage - 2000) * 0.05; }
    if ((wage - START_TAX > 500) && (wage - START_TAX <= 2000))
    {
    tax = (wage - 2000) * 0.1 - 25;
    }
    if (wage - START_TAX > 2000)
    {
    tax = (wage - 2000) * 0.15 - 125;
    }
    return tax;
    }
    }public class Salary
    {
    String employeeId = "";
    double wage = 0;
    static double tax = 0;
    double realWage = 0; public double computeTax()
    {
    tax =Tools.computeTax(wage);
    return tax;
    } public double computeRealWage()
    {
    realWage = wage - this.computeTax();
    return realWage;
    } public static void main(String[] args)
    {
    Salary salary = new Salary();
    Scanner sc = new Scanner(System.in);
    System.out.println("职工号");
    salary.employeeId = sc.nextLine();
    System.out.println("税前工资");
    salary.wage = sc.nextDouble();
    System.out.println("职工号" + salary.employeeId + "税前工资" + salary.wage
    + "扣税" + salary.computeTax() + "实发工资"
    + salary.computeRealWage());
    }
    }
      

  3.   

    +1
    “无法从静态上下文中引用非静态 方法”:
    public double computeTax(){
    tax=Tools.computeTax(wage);
    return tax;
    }
    这里用对类的静态方法调用,没有new Tools().computeTax(wage),
    public double computeTax(double wage)
    声明的是实例方法,只能通过对象实例调用。
    还有return那一句的变量作用域问题。