-6

面向对象编程..我的主要方法有问题,它说找不到符号。为什么?

在这部分:

double grossPay = payroll.getHoursWorked * payroll.getPayRate * payroll.getTaxRate ;

我所知道的是我已经在这里的基类中声明了它:

public class Exercise1 {
    private long hoursWorked;
    private double payRate;
    private double taxRate;   


    public void setHoursWorked(long temp){
        hoursWorked = temp;
    }

    public void setPayRate (double temp){
        payRate = temp;
    }

    public void setTaxRate (double temp){
        taxRate = temp;
    }

    public double getTaxRate (){
        return(taxRate);
    }

    public double getPayRate (){
         return(payRate);
    }

    public double getHoursWorked (){
        return(hoursWorked);
    }
}

这是我的主要课程:

public class payroll{
    public static void main(String args[]){
        Exercise1 payroll = new Exercise1();
        payroll.setHoursWorked(28);
        payroll.setPayRate (120.00);
        payroll.setTaxRate (0.30);

        double grossPay = payroll.getHoursWorked * payroll.getPayRate * payroll.getTaxRate;
        System.out.println("Gross pay is:"+ grossPay);   
    }
}

为什么一直问“找不到符号”?请帮忙..我是编程新手:(

4

6 回答 6

4

getHoursWorkedgetPayRate方法,即使你没有传递参数,它们仍然需要空括号才能被调用。

用 替换它们getHoursWorked()getPayRate()你会笑的。

于 2013-01-07T13:08:16.623 回答
3

您在函数调用结束时忘记了 ()。

double grossPay = payroll.getHoursWorked() * payroll.getPayRate() * payroll.getTaxRate();
于 2013-01-07T13:07:29.670 回答
3

用这个

double grossPay = payroll.getHoursWorked() * payroll.getPayRate() * payroll.getTaxRate() ;

因为getHoursWorked是方法,所以你需要这样调用方法payroll.getHoursWorked()

于 2013-01-07T13:08:04.167 回答
1

您应该使用 () 调用方法;括号调用方法。喜欢-

payroll.getHoursWorked() * payroll.getPayRate()
于 2013-01-07T13:11:43.423 回答
1

将 () 放在每个 func 调用的末尾。

于 2013-01-07T13:09:00.817 回答
1

尝试这个:

double grossPay = payroll.getHoursWorked() * payroll.getPayRate() * payroll.getTaxRate() ;
于 2013-01-07T13:09:29.940 回答