简体   繁体   English

赋值的左侧不是变量?

[英]the left hand side of the assignment is not a variable?

I am trying to set this up so my tests will work but I keep getting an error about the left-hand side of the assignment is not a variable on the line starting with 'flunking.gpa...'. 我试图设置它,所以我的测试将工作,但我一直得到一个关于赋值左侧的错误不是从'flunking.gpa ...'开始的行上的变量。 Any suggestions as to what i am doing wrong? 关于我做错了什么的任何建议?

/**
 * After we have added hours and quality points, we need to 
 * check that the gpa is (quality points) / hours
 */ 
@Test
public void gpa() {  
    flunking.gpa() = flunking.qualityPoints() / (double)flunking.hours();
    assertEquals(flunking.gpa(), 0.0, DELTA);
}

You're attempting to assign a value to a method 您正在尝试为方法分配值

flunking.gpa() = flunking.qualityPoints() / (double)flunking.hours();

As both qualityPoints and hours contain values within the flunking classs, there's should be no need for any assignment here, ie just have gpa return the calculated value in that class as required, eg 由于qualityPointshours都包含了flunking类中的值,因此这里不需要任何赋值,即只需要gpa根据需要返回该类中的计算值,例如

public double getGPA() {
   return qualityPoints / (double)hours; 
}

Perhaps there is a flunking.setGpa(newValue) or flunking.gpa(newValue) method to change the value? 也许有一个flunking.setGpa(newValue)flunking.gpa(newValue)方法来改变这个值? .gpa() just returns the value and it doesn't make sense to assign to it, technically speaking. .gpa()只返回值,从技术上讲,分配给它是没有意义的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM