2015-10-14 63 views
1

试图弄清楚我将如何为此方法构建方法声明。如何编写方法声明java

double cost = School.getCost(782.42, new Student(int credits)); 

这就是我到目前为止所提出的。

public void getCost(double in_cost, //not sure what to do here?) 

回答

0

应该

public static void getCost(double in_cost, Student student) 

这是静态的,因为你调用的方式。

0

尝试以下操作:

public static void getCost(double in_cost, Student student) 
+1

应该是静态的。 –

0

你分配无效翻一番,并最终方法看起来像

public static double getCost(double in_cost, Student student) 
{ 
double result; 
    int student_credits=student.credits; 

    // calculations 

    return result; 

} 
0

在代码中,你分配方法的返回值的double其表示方法的返回值必须为double

public static double getCost 

现在我们来看看参数列表,该方法需要一个浮点数和一个Student对象。我们可以推断出第二个参数必须是Student。那么第一个呢?这是一个floatdouble?因为它不具有任何后缀,如Ff,它是一个double

public static double getCost (double d, Student s) { 

} 

在上面的代码中的参数arbitary,如果你愿意,你可以提供更多有意义的名字给他们。