我一直很难把这个项目放在一起。我们的想法是用实例变量和扫描仪计算课堂上学生的平均成绩。我理解作业的输出和输入部分,但我正在努力编写下面的代码。
public class Averages extends Object
{
// Put any attributes / instance variables here. */
private String name;
// create grade1, grade2, and your Scanner.
// Constructor
public Classroom ()
{
// initialize any attributes that need initial values here */
// initialize your Scanner
return;
}
然后一旦创建,我应该修改我的原始编码,以便它使用实例变量而不是参数变量。这是我最初的原因:
public double calcAverage (double a, double b)
{
return ((a + b) /2.0);
}
答案 0 :(得分:-1)
public class Averages extends Object
{
// Put any attributes / instance variables here.
private String name;
// create grade1, grade2, and your Scanner.
// Constructor must have the same name as the class
public Averages()
{
// initialize any attributes that need initial values here `
// initialize your Scanner
}
}
I simply corrected your constructor, the constructor name must match the classname