开发者

Equals method with oop using java

i need to write a method that returns true of o is a quarterback and the o's first name, last name, attempts, completions, yards, int开发者_Go百科erceptions and touchdowns are all equal to this quarterback's corresponding properties. here is what i got and im stuck with this equals method. can someone get me started with it, im new to this

public class Quarterback {

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()
{

}

}


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};
}


Assuming you want to pass a Quarterback object to your equals function you would have to call your different get functions to get the corresponding information for o, then compare it to the object itself. It would look something like this.

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

This is just an idea to get you started there.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜