2017-05-14 1 views
0

나는이 프로젝트를 진행하는 데 어려움을 겪고있다. 아이디어는 인스턴스 변수와 스캐너를 사용하여 교실에서 학생의 평균 성적을 계산하는 것이 었습니다. 과제의 출력 및 입력 부분을 이해하지만 아래의 코딩에 어려움을 겪고 있습니다.속성과 스캐너뿐만 아니라 인스턴스 변수 초기화

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); 
} 
+2

코드는 이해가되지 않습니다 : 생성자는 클래스 이름과 일치하지 않습니다. "extends Object"는 생성자 내에서 돌아올뿐 아니라 필요한 것입니다. – efekctive

+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 
+0

답을 설명하십시오. – user1803551

관련 문제