为什么这个 mutator 方法在调用之后仍会返回错误?

Why is this mutator method returning an error even after calling it?

我从 class 'Holiday' 中调用了 'setPrice()' 增变器方法,该方法保存 'double' 作为数据类型。但是,当我添加 'holiday.setPrice()' 时,它显示 "method setPrice in Holiday class cannot be applied to the given types: double"。我很困惑为什么会这样。

public void checkOut(Member member, Holiday holiday){
        if(member.getBalance() >= holiday.getPrice()){
            System.out.println("Transaction complete"); 
            System.out.println("You have been automatically logged off");
             member.setLoginStatus(false);
             if(checkHitDiscount() == true){
             holiday.setPrice() = discount - holiday.getPrice() ;
             System.out.println(" Good news! You're eligible for a discount!");
            }else{
                System.out.println("No discount available, try again next time");
            }
        } else { 
                System.out.println("You don't have suffiencient funds");
            }
    }

您正在尝试使用以下行:

holiday.setPrice() = discount - holiday.getPrice();

这应该是

holiday.setPrice(discount - holiday.getPrice());

相反。函数的输入在其括号内。

编辑:discountholiday.getPrice() 也应该根据它们的名称颠倒过来。

EDIT2:您现有的代码试图做的是将 discount - holiday.getPrice() 的值分配给没有输入的假设 holiday.setPrice() 返回的双精度值。这是不允许的,因为那是一个值,而不是一个变量(即:一个名称指的是内存中存储一​​个值的位置)。这有点像试图执行 5 = 3 + 4;.