2011-03-19 4 views
0

o의 true를 반환하는 메소드를 작성해야합니다. 쿼터백이며 o의 이름, 성, 시도, 완료, 야드, 인터셉션 및 터치 다운은 모두이 쿼터백의 해당 속성과 같습니다. 여기에 내가 가지고있는 것과 im이 this equals 메서드로 붙어있다. 누군가가 내가 그것을 시작할 수 있습니다, 당신은 당신의 등호는 것 함수에 쿼터백 객체를 전달하려는 가정이자바를 사용하여 oop를 사용하는 equals 메소드

공용 클래스 쿼터백 {

private int attempts; 
private int completions; 
private String firstName; 
private int interceptions; 
private String lastName; 
private int touchdowns; 
private int yards; 
//************************************************************ 
public Quarterback() 
{ 
    new Quarterback(); 
} 

//**************************************************************** 

public Quarterback(String firstName, String lastName, int completions, int attempts, int yards, int interceptions, int touchdowns) 
{ 
    this.firstName = firstName; 
    this.lastName = lastName; 
    this.completions = completions; 
    this.attempts = attempts; 
    this.yards = yards; 
    this.interceptions = interceptions; 
    this.touchdowns = touchdowns; 

} 

    //***************************************************************** 

public Quarterback copy() 
{ 
    Quarterback o = new Quarterback(); 
    o.firstName = this.firstName; 
    o.lastName = this.lastName; 
    o.completions = this.completions; 
    o.attempts = this.attempts; 
    o.yards = this.yards; 
    o.interceptions = this.interceptions; 
    o.touchdowns = this.touchdowns; 
    return o; 



} 

    //******************************************************************  

public boolean equals(Object o) 
{ 

} 

    //********************************************************************* 

public int getAttempts() 
{ 
    return this.attempts; 
} 

    //******************************************************************************* 

public int getCompletions() 
{ 
    return this.completions; 
} 

    //******************************************************************************* 

public String getFirstName() 
{ 
    return this.firstName; 
} 

    //******************************************************************************* 

public int getInterceptions() 
{ 
    return this.interceptions; 

} 

    //**************************************************************************** 

public String getLastName() 
{ 
    return this.lastName; 
} 
//**************************************************************************** 

public void getRating() 
{ 

} 

//**************************************************************************** 

public int getTouchdowns() 
{ 
    return this.touchdowns; 

} 

//***************************************************************************** 

public int getYards() 
{ 
    return this.yards; 
} 

//******************************************************************************* 

public void setAttempts(int attempts) 
{ 
    this.attempts = attempts; 

} 

//******************************************************************************* 

public void setCompletions(int completions) 
{ 
    this.completions = completions; 

} 

//******************************************************************************* 

public void setFirstName(String firstName) 
{ 
    this.firstName = firstName; 

} 
//******************************************************************************* 

public void setInterceptions(int interceptions) 
{ 
    this.interceptions = interceptions; 
} 
//*****************************************************************************  

public void setLastName(String lastName) 
{ 
this.lastName = lastName; 
    //***************************************************************************** 

public void setTouchdowns(int touchdowns) 
{ 
    this.touchdowns = touchdowns; 
} 
    //***************************************************************************** 

public void setYards(int yards) 
{ 
    this.yards = yards; 
} 
//***************************************************************************** 

public String toString() 
{ 

} 

}

+0

이전 질문에서 'equals'을 구현하는 방법에 대한 답변을 이미 얻었습니다. 힌트 - 당신이 질문을 할 때 SO ... ** 답변을 읽어보십시오 **. –

답변

0
public boolean equals(Object o) 
{ 
    if(!o instanceof Quarterback) 
     return false; 
    Quarterback q = (Quarterback)o; 
    return this.firstName.equals(q.getFirstName()) && this.lastName.equals(q.getLastName()) && this.attempts == q.getAttempts() && {the rest of the variables}; 
} 
0

에 새로운 메신저 다른 get 함수를 호출하여 o에 해당하는 정보를 얻은 다음 객체 자체와 비교해야합니다. 이런 식으로 보일 겁니다.

public boolean equals(Object o) 
{ 
    if !(o.getAttempts() == this.attempts) return false; 
} 

이것은 처음 시작했을 때의 생각입니다.

관련 문제