试图弄清楚我将如何为此方法构建方法声明。如何编写方法声明java
double cost = School.getCost(782.42, new Student(int credits));
这就是我到目前为止所提出的。
public void getCost(double in_cost, //not sure what to do here?)
试图弄清楚我将如何为此方法构建方法声明。如何编写方法声明java
double cost = School.getCost(782.42, new Student(int credits));
这就是我到目前为止所提出的。
public void getCost(double in_cost, //not sure what to do here?)
应该
public static void getCost(double in_cost, Student student)
这是静态的,因为你调用的方式。
尝试以下操作:
public static void getCost(double in_cost, Student student)
你分配无效翻一番,并最终方法看起来像
public static double getCost(double in_cost, Student student)
{
double result;
int student_credits=student.credits;
// calculations
return result;
}
在代码中,你分配方法的返回值的double
其表示方法的返回值必须为double
:
public static double getCost
现在我们来看看参数列表,该方法需要一个浮点数和一个Student
对象。我们可以推断出第二个参数必须是Student
。那么第一个呢?这是一个float
double
?因为它不具有任何后缀,如F
或f
,它是一个double
:
public static double getCost (double d, Student s) {
}
在上面的代码中的参数arbitary,如果你愿意,你可以提供更多有意义的名字给他们。
应该是静态的。 –